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 booleanflag for AYTprivate final Objectmonitor to wait for AYT(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 boolean(package private) static final boolean(package private) static final int(package private) static final intprivate final int[]private TelnetNotificationHandlerThe notification handlerprivate final TelnetOptionHandler[]Array of option handlersprivate final int[](package private) static final int(package private) static final intprivate OutputStreamThe stream on which to spyprotected static final intTerminal type optionprotected static final intIs (for subnegotiation)protected static final intSend (for subnegotiation)private StringTerminal type(package private) static final intprivate final int[]Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalled upon connection.(package private) void_registerSpyStream(OutputStream spystream) Registers an OutputStream for spying what's going on in the Telnet session.(package private) final booleanSends anAre You There (AYT)sequence and waits for the result.(package private) final void_sendCommand(byte cmd) Sends a command, automatically adds IAC prefix and flushes the output.(package private) final void_sendSubnegotiation(int[] subn) Manages subnegotiation for Terminal Type.(package private) voidStops 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.(package private) final voidProcesses the response of an AYT(package private) voidprocessCommand(int command) Processes a COMMAND.(package private) voidprocessDo(int option) Processes aDOrequest.(package private) voidprocessDont(int option) Processes aDONTrequest.(package private) voidprocessSuboption(int[] suboption, int suboptionLength) Processes a suboption negotiation.(package private) voidprocessWill(int option) Processes aWILLrequest.(package private) voidprocessWont(int option) Processes aWONTrequest.voidregisterNotifHandler(TelnetNotificationHandler notifhand) Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.(package private) final voidrequestDo(int option) Requests a DO.(package private) final voidrequestDont(int option) Requests aDONT.(package private) booleanrequestedDo(int option) Looks for the state of the option.(package private) booleanrequestedDont(int option) Looks for the state of the option.(package private) booleanrequestedWill(int option) Looks for the state of the option.(package private) booleanrequestedWont(int option) Looks for the state of the option.(package private) final voidrequestWill(int option) Requests aWILL.(package private) final voidrequestWont(int option) Requests aWONT.(package private) final voidsendByte(int b) Sends a byte.(package private) final voidsendDo(int option) Sends aDO.(package private) final voidsendDont(int option) Sends aDONT.(package private) final voidSends terminal type information.(package private) final voidsendWill(int option) Sends aWILL.(package private) final voidsendWont(int option) Sends aWONT.(package private) voidsetDo(int option) Sets the state of the option.(package private) voidsetDont(int option) Sets the state of the option.(package private) voidsetWantDo(int option) Sets the state of the option.(package private) voidsetWantDont(int option) Sets the state of the option.(package private) voidsetWantWill(int option) Sets the state of the option.(package private) voidsetWantWont(int option) Sets the state of the option.(package private) voidsetWill(int option) Sets the state of the option.(package private) voidsetWont(int option) Sets the state of the option.(package private) voidspyRead(int ch) Sends a read char on the spy stream.(package private) voidspyWrite(int ch) Sends a written char on the spy stream.(package private) booleanstateIsDo(int option) Looks for the state of the option.(package private) booleanstateIsDont(int option) Looks for the state of the option.(package private) booleanstateIsWill(int option) Looks for the state of the option.(package private) booleanstateIsWont(int option) Looks for the state of the option.voidUnregisters the current notification handler.Methods inherited from class org.apache.commons.net.SocketClient
addProtocolCommandListener, applySocketAttributes, connect, connect, connect, connect, connect, connect, createCommandSupport, disconnect, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getCommandSupport, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, 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:
-
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) -
COMMAND_AYT
static final byte[] COMMAND_AYTAYT sequence -
doResponse
private final int[] doResponse -
willResponse
private final int[] willResponse -
options
private final int[] options -
terminalType
Terminal type -
optionHandlers
Array of option handlers -
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
-
_connectAction_
Called upon connection.- Overrides:
_connectAction_in classSocketClient- Throws:
IOException- - Exception in I/O.
-
_registerSpyStream
Registers an OutputStream for spying what's going on in the Telnet session.- Parameters:
spystream- - OutputStream on which session activity will be echoed.
-
_sendAYT
final boolean _sendAYT(Duration timeout) throws IOException, IllegalArgumentException, InterruptedException Sends anAre You There (AYT)sequence and waits for the result.- Parameters:
timeout- - Time to wait for a response.- Returns:
- true if AYT received a response, false otherwise
- Throws:
IOException- - Exception in I/O.IllegalArgumentException- - Illegal argumentInterruptedException- - Interrupted during wait.
-
_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
-
_sendSubnegotiation
Manages subnegotiation for Terminal Type.- Parameters:
subn- - subnegotiation data to be sent- Throws:
IOException- - Exception in I/O.
-
_stopSpyStream
void _stopSpyStream()Stops spying this Telnet. -
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
-
processAYTResponse
final void processAYTResponse()Processes the response of an AYT -
processCommand
void processCommand(int command) Processes a COMMAND.- Parameters:
command- - option code to be set.
-
processDo
Processes aDOrequest.- Parameters:
option- - option code to be set.- Throws:
IOException- - Exception in I/O.
-
processDont
Processes aDONTrequest.- 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.
-
processWill
Processes aWILLrequest.- Parameters:
option- - option code to be set.- Throws:
IOException- - Exception in I/O.
-
processWont
Processes aWONTrequest.- Parameters:
option- - option code to be set.- Throws:
IOException- - Exception in I/O.
-
registerNotifHandler
Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.- Parameters:
notifhand- - TelnetNotificationHandler to be registered
-
requestDo
Requests a DO.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
requestDont
Requests aDONT.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
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
DOhas been requested.
-
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
DONThas been requested
-
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
WILLhas been requested
-
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
WONThas been requested
-
requestWill
Requests aWILL.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
requestWont
Requests aWONT.- 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.
-
sendDo
Sends aDO.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
sendDont
Sends aDONT.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
sendTerminalType
Sends terminal type information.- Throws:
IOException- - Exception in I/O.
-
sendWill
Sends aWILL.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
sendWont
Sends aWONT.- Parameters:
option- - Option code.- Throws:
IOException- - Exception in I/O.
-
setDo
Sets the state of the option.- Parameters:
option- - option code to be set.- Throws:
IOException
-
setDont
void setDont(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.
-
setWantDont
void setWantDont(int option) Sets the state of the option.- Parameters:
option- - option code to be set.
-
setWantWill
void setWantWill(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.
-
setWill
Sets the state of the option.- Parameters:
option- - option code to be set.- Throws:
IOException
-
setWont
void setWont(int option) Sets the state of the option.- Parameters:
option- - option code to be set.
-
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
-
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
DOhas 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
DONThas been acknowledged
-
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
WILLhas 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
WONThas been acknowledged
-
unregisterNotifHandler
public void unregisterNotifHandler()Unregisters the current notification handler.
-