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 boolean
aytFlag
flag for AYTprivate java.lang.Object
aytMonitor
monitor to wait for AYT(package private) static byte[]
COMMAND_AYT
AYT sequence(package private) static byte[]
COMMAND_DO
(package private) static byte[]
COMMAND_DONT
(package private) static byte[]
COMMAND_IS
Is 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 boolean
debug
(package private) static boolean
debugoptions
(package private) static int
DEFAULT_PORT
(package private) static int
DO_MASK
private int[]
doResponse
private TelnetNotificationHandler
notifhand
The notification handlerprivate TelnetOptionHandler[]
optionHandlers
Array of option handlersprivate int[]
options
(package private) static int
REQUESTED_DO_MASK
(package private) static int
REQUESTED_WILL_MASK
private java.io.OutputStream
spyStream
The stream on which to spyprotected static int
TERMINAL_TYPE
Terminal type optionprotected static int
TERMINAL_TYPE_IS
Is (for subnegotiation)protected static int
TERMINAL_TYPE_SEND
Send (for subnegotiation)private java.lang.String
terminalType
Terminal type(package private) static int
WILL_MASK
private int[]
willResponse
-
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
_registerSpyStream(java.io.OutputStream spystream)
Registers an OutputStream for spying what's going on in the Telnet session.(package private) boolean
_sendAYT(long timeout)
Sends an Are You There sequence and waits for the result.(package private) void
_sendCommand(byte cmd)
Sends a command, automatically adds IAC prefix and flushes the output.(package private) void
_sendSubnegotiation(int[] subn)
Manages subnegotiation for Terminal Type.(package private) void
_stopSpyStream()
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.(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.void
registerNotifHandler(TelnetNotificationHandler notifhand)
Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.(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) void
sendByte(int b)
Sends a byte.(package private) void
sendDo(int option)
Sends a DO.(package private) void
sendDont(int option)
Sends a DONT.(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.void
unregisterNotifHandler()
Unregisters 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, 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
-
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)
-
COMMAND_AYT
static final byte[] COMMAND_AYT
AYT sequence
-
doResponse
private final int[] doResponse
-
willResponse
private final int[] willResponse
-
options
private final int[] options
-
terminalType
private java.lang.String terminalType
Terminal type
-
optionHandlers
private final TelnetOptionHandler[] optionHandlers
Array of option handlers
-
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
-
_connectAction_
protected void _connectAction_() throws java.io.IOException
Called upon connection.- Overrides:
_connectAction_
in classSocketClient
- Throws:
java.io.IOException
- - Exception in I/O.
-
_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.
-
_sendAYT
final boolean _sendAYT(long timeout) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.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:
java.io.IOException
- - Exception in I/O.java.lang.IllegalArgumentException
- - Illegal argumentjava.lang.InterruptedException
- - Interrupted during wait.
-
_sendCommand
final void _sendCommand(byte cmd) throws java.io.IOException
Sends 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
-
_sendSubnegotiation
final void _sendSubnegotiation(int[] subn) throws java.io.IOException
Manages subnegotiation for Terminal Type.- Parameters:
subn
- - subnegotiation data to be sent- Throws:
java.io.IOException
- - Exception in I/O.
-
_stopSpyStream
void _stopSpyStream()
Stops spying this Telnet.
-
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.IOException
Unregisters a TelnetOptionHandler.- Parameters:
optcode
- - Code of the option to be unregistered.- Throws:
InvalidTelnetOptionException
- - The option code is invalid.java.io.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
void processDo(int option) throws java.io.IOException
Processes 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.IOException
Processes a DONT 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.IOException
Processes a suboption negotiation.- Parameters:
suboption
- - subnegotiation data receivedsuboptionLength
- - length of data received- Throws:
java.io.IOException
- - Exception in I/O.
-
processWill
void processWill(int option) throws java.io.IOException
Processes 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.IOException
Processes a WONT request.- Parameters:
option
- - option code to be set.- Throws:
java.io.IOException
- - Exception in I/O.
-
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
-
requestDo
final void requestDo(int option) throws java.io.IOException
Requests a DO.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
requestDont
final void requestDont(int option) throws java.io.IOException
Requests a DONT.- Parameters:
option
- - Option code.- Throws:
java.io.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 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
-
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
-
requestWill
final void requestWill(int option) throws java.io.IOException
Requests a WILL.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
requestWont
final void requestWont(int option) throws java.io.IOException
Requests a WONT.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
sendByte
final void sendByte(int b) throws java.io.IOException
Sends a byte.- Parameters:
b
- - byte to send- Throws:
java.io.IOException
- - Exception in I/O.
-
sendDo
final void sendDo(int option) throws java.io.IOException
Sends a DO.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
sendDont
final void sendDont(int option) throws java.io.IOException
Sends a DONT.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
sendTerminalType
final void sendTerminalType() throws java.io.IOException
Sends terminal type information.- Throws:
java.io.IOException
- - Exception in I/O.
-
sendWill
final void sendWill(int option) throws java.io.IOException
Sends a WILL.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
sendWont
final void sendWont(int option) throws java.io.IOException
Sends a WONT.- Parameters:
option
- - Option code.- Throws:
java.io.IOException
- - Exception in I/O.
-
setDo
void setDo(int option) throws java.io.IOException
Sets the state of the option.- Parameters:
option
- - option code to be set.- Throws:
java.io.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
void setWill(int option) throws java.io.IOException
Sets the state of the option.- Parameters:
option
- - option code to be set.- Throws:
java.io.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 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
-
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
-
unregisterNotifHandler
public void unregisterNotifHandler()
Unregisters the current notification handler.
-
-