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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate TelnetNotificationHandler
The notification handler(package private) static final byte[]
AYT sequence(package private) static final byte[]
(package private) static final byte[]
(package private) static final byte[]
Is sequence (for subnegotiation)(package private) static final byte[]
(package private) static final byte[]
(package private) static final byte[]
(package private) static final byte[]
(package private) static final int
(package private) int[]
(package private) int[]
(package private) static final int
(package private) static final int
(package private) static final int
(package private) int[]
private boolean
flag for AYTprivate final Object
monitor to wait for AYT(package private) static final boolean
(package private) static final boolean
(package private) static final int
private final TelnetOptionHandler[]
Array of option handlersprivate OutputStream
The stream on which to spyprotected static final int
Terminal type optionprotected static final int
Is (for subnegotiation)protected static final int
Send (for subnegotiation)private String
Terminal typeFields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Called upon connection.(package private) final void
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
(OutputStream spystream) Registers an OutputStream for spying what's going on in the Telnet session.(package private) final void
_requestDo
(int option) Requests a DO.(package private) final 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) final void
_requestWill
(int option) Requests a WILL.(package private) final void
_requestWont
(int option) Requests a WONT.(package private) final boolean
_sendAYT
(long timeout) Sends an Are You There sequence and waits for the result.(package private) final void
_sendByte
(int b) Sends a byte.(package private) final void
_sendCommand
(byte cmd) Sends a command, automatically adds IAC prefix and flushes the output.(package private) final void
_sendDo
(int option) Sends a DO.(package private) final void
_sendDont
(int option) Sends a DONT.(package private) final void
_sendSubnegotiation
(int[] subn) Manages subnegotiation for Terminal Type.(package private) final void
Sends terminal type information.(package private) final void
_sendWill
(int option) Sends a WILL.(package private) final 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
Stops spying this Telnet.(package private) void
addOptionHandler
(TelnetOptionHandler opthand) Registers a new TelnetOptionHandler for this telnet to use.(package private) void
deleteOptionHandler
(int optcode) Unregisters a TelnetOptionHandler.void
registerNotifHandler
(TelnetNotificationHandler notifhand) Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.void
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 Details
-
debug
static final boolean debug- See Also:
-
debugoptions
static final boolean debugoptions- See Also:
-
_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:
-
_DO_MASK
static final int _DO_MASK- See Also:
-
_REQUESTED_WILL_MASK
static final int _REQUESTED_WILL_MASK- See Also:
-
_REQUESTED_DO_MASK
static final int _REQUESTED_DO_MASK- See Also:
-
DEFAULT_PORT
static final int DEFAULT_PORT- See Also:
-
_doResponse
int[] _doResponse -
_willResponse
int[] _willResponse -
_options
int[] _options -
TERMINAL_TYPE
protected static final int TERMINAL_TYPETerminal type option- See Also:
-
TERMINAL_TYPE_SEND
protected static final int TERMINAL_TYPE_SENDSend (for subnegotiation)- See Also:
-
TERMINAL_TYPE_IS
protected static final int TERMINAL_TYPE_ISIs (for subnegotiation)- See Also:
-
_COMMAND_IS
static final byte[] _COMMAND_ISIs sequence (for subnegotiation) -
terminalType
Terminal type -
optionHandlers
Array of option handlers -
_COMMAND_AYT
static final byte[] _COMMAND_AYTAYT sequence -
aytMonitor
monitor to wait for AYT -
aytFlag
private volatile boolean aytFlagflag for AYT -
spyStream
The stream on which to spy -
__notifhand
The notification handler
-
-
Constructor Details
-
Telnet
Telnet()Empty Constructor -
Telnet
Telnet(String termtype) This constructor lets you specify the terminal type.- Parameters:
termtype
- - terminal type to be negotiated (ej. VT100)
-
-
Method Details
-
_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
Sets the state of the option.- Parameters:
option
- - option code to be set.- Throws:
IOException
-
_setDo
Sets the state of the option.- Parameters:
option
- - option code to be set.- Throws:
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
Processes a DO request.- Parameters:
option
- - option code to be set.- Throws:
IOException
- - Exception in I/O.
-
_processDont
Processes a DONT request.- Parameters:
option
- - option code to be set.- Throws:
IOException
- - Exception in I/O.
-
_processWill
Processes a WILL request.- Parameters:
option
- - option code to be set.- Throws:
IOException
- - Exception in I/O.
-
_processWont
Processes a WONT request.- Parameters:
option
- - option code to be set.- Throws:
IOException
- - Exception in I/O.
-
_processSuboption
Processes a suboption negotiation.- Parameters:
suboption
- - subnegotiation data receivedsuboptionLength
- - length of data received- Throws:
IOException
- - Exception in I/O.
-
_sendTerminalType
Sends terminal type information.- Throws:
IOException
- - Exception in I/O.
-
_sendSubnegotiation
Manages subnegotiation for Terminal Type.- Parameters:
subn
- - subnegotiation data to be sent- Throws:
IOException
- - Exception in I/O.
-
_sendCommand
Sends a command, automatically adds IAC prefix and flushes the output.- Parameters:
cmd
- - command data to be sent- Throws:
IOException
- - Exception in I/O.- Since:
- 3.0
-
_processAYTResponse
final void _processAYTResponse()Processes the response of an AYT -
_connectAction_
Called upon connection.- Overrides:
_connectAction_
in classSocketClient
- Throws:
IOException
- - Exception in I/O.
-
_sendDo
Sends a DO.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_requestDo
Requests a DO.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_sendDont
Sends a DONT.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_requestDont
Requests a DONT.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_sendWill
Sends a WILL.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_requestWill
Requests a WILL.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_sendWont
Sends a WONT.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_requestWont
Requests a WONT.- Parameters:
option
- - Option code.- Throws:
IOException
- - Exception in I/O.
-
_sendByte
Sends a byte.- Parameters:
b
- - byte to send- Throws:
IOException
- - Exception in I/O.
-
_sendAYT
final boolean _sendAYT(long timeout) throws IOException, IllegalArgumentException, InterruptedException Sends 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:
IOException
- - Exception in I/O.IllegalArgumentException
- - Illegal argumentInterruptedException
- - Interrupted during wait.
-
addOptionHandler
Registers a new TelnetOptionHandler for this telnet to use.- Parameters:
opthand
- - option handler to be registered.- Throws:
InvalidTelnetOptionException
- - The option code is invalid.IOException
- on error
-
deleteOptionHandler
Unregisters a TelnetOptionHandler.- Parameters:
optcode
- - Code of the option to be unregistered.- Throws:
InvalidTelnetOptionException
- - The option code is invalid.IOException
- on error
-
_registerSpyStream
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
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.
-