Package org.apache.commons.net.telnet
Class Telnet
- java.lang.Object
-
- org.apache.commons.net.SocketClient
-
- org.apache.commons.net.telnet.Telnet
-
- Direct Known Subclasses:
TelnetClient
class Telnet extends SocketClient
-
-
Field Summary
Fields Modifier and Type Field Description private TelnetNotificationHandler__notifhandThe notification handler(package private) static byte[]_COMMAND_AYTAYT sequence(package private) static byte[]_COMMAND_DO(package private) static byte[]_COMMAND_DONT(package private) static byte[]_COMMAND_ISIs sequence (for subnegotiation)(package private) static byte[]_COMMAND_SB(package private) static byte[]_COMMAND_SE(package private) static byte[]_COMMAND_WILL(package private) static byte[]_COMMAND_WONT(package private) static int_DO_MASK(package private) int[]_doResponse(package private) int[]_options(package private) static int_REQUESTED_DO_MASK(package private) static int_REQUESTED_WILL_MASK(package private) static int_WILL_MASK(package private) int[]_willResponseprivate booleanaytFlagflag for AYTprivate java.lang.ObjectaytMonitormonitor to wait for AYT(package private) static booleandebug(package private) static booleandebugoptions(package private) static intDEFAULT_PORTprivate TelnetOptionHandler[]optionHandlersArray of option handlersprivate java.io.OutputStreamspyStreamThe stream on which to spyprotected static intTERMINAL_TYPETerminal type optionprotected static intTERMINAL_TYPE_ISIs (for subnegotiation)protected static intTERMINAL_TYPE_SENDSend (for subnegotiation)private java.lang.StringterminalTypeTerminal type-
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void_connectAction_()Called upon connection.(package private) void_processAYTResponse()Processes the response of an AYT(package private) void_processCommand(int command)Processes a COMMAND.(package private) void_processDo(int option)Processes a DO request.(package private) void_processDont(int option)Processes a DONT request.(package private) void_processSuboption(int[] suboption, int suboptionLength)Processes a suboption negotiation.(package private) void_processWill(int option)Processes a WILL request.(package private) void_processWont(int option)Processes a WONT request.(package private) void_registerSpyStream(java.io.OutputStream spystream)Registers an OutputStream for spying what's going on in the Telnet session.(package private) void_requestDo(int option)Requests a DO.(package private) void_requestDont(int option)Requests a DONT.(package private) boolean_requestedDo(int option)Looks for the state of the option.(package private) boolean_requestedDont(int option)Looks for the state of the option.(package private) boolean_requestedWill(int option)Looks for the state of the option.(package private) boolean_requestedWont(int option)Looks for the state of the option.(package private) void_requestWill(int option)Requests a WILL.(package private) void_requestWont(int option)Requests a WONT.(package private) boolean_sendAYT(long timeout)Sends an Are You There sequence and waits for the result.(package private) void_sendByte(int b)Sends a byte.(package private) void_sendCommand(byte cmd)Sends a command, automatically adds IAC prefix and flushes the output.(package private) void_sendDo(int option)Sends a DO.(package private) void_sendDont(int option)Sends a DONT.(package private) void_sendSubnegotiation(int[] subn)Manages subnegotiation for Terminal Type.(package private) void_sendTerminalType()Sends terminal type information.(package private) void_sendWill(int option)Sends a WILL.(package private) void_sendWont(int option)Sends a WONT.(package private) void_setDo(int option)Sets the state of the option.(package private) void_setDont(int option)Sets the state of the option.(package private) void_setWantDo(int option)Sets the state of the option.(package private) void_setWantDont(int option)Sets the state of the option.(package private) void_setWantWill(int option)Sets the state of the option.(package private) void_setWantWont(int option)Sets the state of the option.(package private) void_setWill(int option)Sets the state of the option.(package private) void_setWont(int option)Sets the state of the option.(package private) void_spyRead(int ch)Sends a read char on the spy stream.(package private) void_spyWrite(int ch)Sends a written char on the spy stream.(package private) boolean_stateIsDo(int option)Looks for the state of the option.(package private) boolean_stateIsDont(int option)Looks for the state of the option.(package private) boolean_stateIsWill(int option)Looks for the state of the option.(package private) boolean_stateIsWont(int option)Looks for the state of the option.(package private) void_stopSpyStream()Stops spying this Telnet.(package private) voidaddOptionHandler(TelnetOptionHandler opthand)Registers a new TelnetOptionHandler for this telnet to use.(package private) voiddeleteOptionHandler(int optcode)Unregisters a TelnetOptionHandler.voidregisterNotifHandler(TelnetNotificationHandler notifhand)Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.voidunregisterNotifHandler()Unregisters the current notification handler.-
Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, connect, connect, connect, connect, connect, connect, createCommandSupport, disconnect, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
-
-
-
-
Field Detail
-
debug
static final boolean debug
- See Also:
- Constant Field Values
-
debugoptions
static final boolean debugoptions
- See Also:
- Constant Field Values
-
_COMMAND_DO
static final byte[] _COMMAND_DO
-
_COMMAND_DONT
static final byte[] _COMMAND_DONT
-
_COMMAND_WILL
static final byte[] _COMMAND_WILL
-
_COMMAND_WONT
static final byte[] _COMMAND_WONT
-
_COMMAND_SB
static final byte[] _COMMAND_SB
-
_COMMAND_SE
static final byte[] _COMMAND_SE
-
_WILL_MASK
static final int _WILL_MASK
- See Also:
- Constant Field Values
-
_DO_MASK
static final int _DO_MASK
- See Also:
- Constant Field Values
-
_REQUESTED_WILL_MASK
static final int _REQUESTED_WILL_MASK
- See Also:
- Constant Field Values
-
_REQUESTED_DO_MASK
static final int _REQUESTED_DO_MASK
- See Also:
- Constant Field Values
-
DEFAULT_PORT
static final int DEFAULT_PORT
- See Also:
- Constant Field Values
-
_doResponse
int[] _doResponse
-
_willResponse
int[] _willResponse
-
_options
int[] _options
-
TERMINAL_TYPE
protected static final int TERMINAL_TYPE
Terminal type option- See Also:
- Constant Field Values
-
TERMINAL_TYPE_SEND
protected static final int TERMINAL_TYPE_SEND
Send (for subnegotiation)- See Also:
- Constant Field Values
-
TERMINAL_TYPE_IS
protected static final int TERMINAL_TYPE_IS
Is (for subnegotiation)- See Also:
- Constant Field Values
-
_COMMAND_IS
static final byte[] _COMMAND_IS
Is sequence (for subnegotiation)
-
terminalType
private java.lang.String terminalType
Terminal type
-
optionHandlers
private final TelnetOptionHandler[] optionHandlers
Array of option handlers
-
_COMMAND_AYT
static final byte[] _COMMAND_AYT
AYT sequence
-
aytMonitor
private final java.lang.Object aytMonitor
monitor to wait for AYT
-
aytFlag
private volatile boolean aytFlag
flag for AYT
-
spyStream
private volatile java.io.OutputStream spyStream
The stream on which to spy
-
__notifhand
private TelnetNotificationHandler __notifhand
The notification handler
-
-
Method Detail
-
_stateIsWill
boolean _stateIsWill(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a will has been acknowledged
-
_stateIsWont
boolean _stateIsWont(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a wont has been acknowledged
-
_stateIsDo
boolean _stateIsDo(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a do has been acknowledged
-
_stateIsDont
boolean _stateIsDont(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a dont has been acknowledged
-
_requestedWill
boolean _requestedWill(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a will has been reuqested
-
_requestedWont
boolean _requestedWont(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a wont has been reuqested
-
_requestedDo
boolean _requestedDo(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a do has been reuqested
-
_requestedDont
boolean _requestedDont(int option)
Looks for the state of the option.- Parameters:
option- - option code to be looked up.- Returns:
- returns true if a dont has been reuqested
-
_setWill
void _setWill(int option) throws java.io.IOExceptionSets the state of the option.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException
-
_setDo
void _setDo(int option) throws java.io.IOExceptionSets the state of the option.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException
-
_setWantWill
void _setWantWill(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_setWantDo
void _setWantDo(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_setWont
void _setWont(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_setDont
void _setDont(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_setWantWont
void _setWantWont(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_setWantDont
void _setWantDont(int option)
Sets the state of the option.- Parameters:
option- - option code to be set.
-
_processCommand
void _processCommand(int command)
Processes a COMMAND.- Parameters:
command- - option code to be set.
-
_processDo
void _processDo(int option) throws java.io.IOExceptionProcesses a DO request.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException- - Exception in I/O.
-
_processDont
void _processDont(int option) throws java.io.IOExceptionProcesses a DONT request.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException- - Exception in I/O.
-
_processWill
void _processWill(int option) throws java.io.IOExceptionProcesses a WILL request.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException- - Exception in I/O.
-
_processWont
void _processWont(int option) throws java.io.IOExceptionProcesses a WONT request.- Parameters:
option- - option code to be set.- Throws:
java.io.IOException- - Exception in I/O.
-
_processSuboption
void _processSuboption(int[] suboption, int suboptionLength) throws java.io.IOExceptionProcesses a suboption negotiation.- Parameters:
suboption- - subnegotiation data receivedsuboptionLength- - length of data received- Throws:
java.io.IOException- - Exception in I/O.
-
_sendTerminalType
final void _sendTerminalType() throws java.io.IOExceptionSends terminal type information.- Throws:
java.io.IOException- - Exception in I/O.
-
_sendSubnegotiation
final void _sendSubnegotiation(int[] subn) throws java.io.IOExceptionManages subnegotiation for Terminal Type.- Parameters:
subn- - subnegotiation data to be sent- Throws:
java.io.IOException- - Exception in I/O.
-
_sendCommand
final void _sendCommand(byte cmd) throws java.io.IOExceptionSends a command, automatically adds IAC prefix and flushes the output.- Parameters:
cmd- - command data to be sent- Throws:
java.io.IOException- - Exception in I/O.- Since:
- 3.0
-
_processAYTResponse
final void _processAYTResponse()
Processes the response of an AYT
-
_connectAction_
protected void _connectAction_() throws java.io.IOExceptionCalled upon connection.- Overrides:
_connectAction_in classSocketClient- Throws:
java.io.IOException- - Exception in I/O.
-
_sendDo
final void _sendDo(int option) throws java.io.IOExceptionSends a DO.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_requestDo
final void _requestDo(int option) throws java.io.IOExceptionRequests a DO.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_sendDont
final void _sendDont(int option) throws java.io.IOExceptionSends a DONT.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_requestDont
final void _requestDont(int option) throws java.io.IOExceptionRequests a DONT.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_sendWill
final void _sendWill(int option) throws java.io.IOExceptionSends a WILL.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_requestWill
final void _requestWill(int option) throws java.io.IOExceptionRequests a WILL.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_sendWont
final void _sendWont(int option) throws java.io.IOExceptionSends a WONT.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_requestWont
final void _requestWont(int option) throws java.io.IOExceptionRequests a WONT.- Parameters:
option- - Option code.- Throws:
java.io.IOException- - Exception in I/O.
-
_sendByte
final void _sendByte(int b) throws java.io.IOExceptionSends a byte.- Parameters:
b- - byte to send- Throws:
java.io.IOException- - Exception in I/O.
-
_sendAYT
final boolean _sendAYT(long timeout) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.InterruptedExceptionSends an Are You There sequence and waits for the result.- Parameters:
timeout- - Time to wait for a response (millis.)- Returns:
- true if AYT received a response, false otherwise
- Throws:
java.io.IOException- - Exception in I/O.java.lang.IllegalArgumentException- - Illegal argumentjava.lang.InterruptedException- - Interrupted during wait.
-
addOptionHandler
void addOptionHandler(TelnetOptionHandler opthand) throws InvalidTelnetOptionException, java.io.IOException
Registers a new TelnetOptionHandler for this telnet to use.- Parameters:
opthand- - option handler to be registered.- Throws:
InvalidTelnetOptionException- - The option code is invalid.java.io.IOException- on error
-
deleteOptionHandler
void deleteOptionHandler(int optcode) throws InvalidTelnetOptionException, java.io.IOExceptionUnregisters a TelnetOptionHandler.- Parameters:
optcode- - Code of the option to be unregistered.- Throws:
InvalidTelnetOptionException- - The option code is invalid.java.io.IOException- on error
-
_registerSpyStream
void _registerSpyStream(java.io.OutputStream spystream)
Registers an OutputStream for spying what's going on in the Telnet session.- Parameters:
spystream- - OutputStream on which session activity will be echoed.
-
_stopSpyStream
void _stopSpyStream()
Stops spying this Telnet.
-
_spyRead
void _spyRead(int ch)
Sends a read char on the spy stream.- Parameters:
ch- - character read from the session
-
_spyWrite
void _spyWrite(int ch)
Sends a written char on the spy stream.- Parameters:
ch- - character written to the session
-
registerNotifHandler
public void registerNotifHandler(TelnetNotificationHandler notifhand)
Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.- Parameters:
notifhand- - TelnetNotificationHandler to be registered
-
unregisterNotifHandler
public void unregisterNotifHandler()
Unregisters the current notification handler.
-
-