org.apache.commons.net.telnet

Class Telnet

Known Direct Subclasses:
TelnetClient

(package private) class Telnet
extends SocketClient

Authors:
Daniel F. Savarese
Bruno D'Avanzo

Field Summary

(package private) static int
DEFAULT_PORT
protected static int
TERMINAL_TYPE
Terminal type option
protected static int
TERMINAL_TYPE_IS
Is (for subnegotiation)
protected static int
TERMINAL_TYPE_SEND
Send (for subnegotiation)
(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 int
_DO_MASK
(package private) static int
_REQUESTED_DO_MASK
(package private) static int
_REQUESTED_WILL_MASK
(package private) static int
_WILL_MASK
private TelnetNotificationHandler
__notifhand
The notification handler
(package private) int[]
_doResponse
(package private) int[]
_options
(package private) int[]
_willResponse
private boolean
aytFlag
flag for AYT
private Object
aytMonitor
monitor to wait for AYT
(package private) static boolean
debug
(package private) static boolean
debugoptions
private TelnetOptionHandler[]
optionHandlers
Array of option handlers
private OutputStream
spyStream
The stream on which to spy
private String
terminalType
Terminal type

Fields inherited from class org.apache.commons.net.SocketClient

NETASCII_EOL, __DEFAULT_SOCKET_FACTORY, _defaultPort_, _input_, _isConnected_, _output_, _socketFactory_, _socket_, _timeout_

Constructor Summary

Telnet()
Empty Constructor
Telnet(String termtype)
This constructor lets you specify the terminal type.

Method Summary

protected void
_connectAction_()
Called upon connection.
(package private) void
_processAYTResponse()
Processes the response of an AYT
(package private) void
_processDo(int option)
Processes a DO request.
(package private) void
_processDont(int option)
Processes a DONT request.
(package private) void
_processSuboption(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) void
_requestDo(int option)
Requests a DO.
(package private) void
_requestDont(int option)
Requests a DONT.
(package private) void
_requestWill(int option)
Requests a WILL.
(package private) void
_requestWont(int option)
Requests a WONT.
(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) 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
_sendDo(int option)
Sends a DO.
(package private) void
_sendDont(int option)
Sends a DONT.
(package private) void
_sendSubnegotiation(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) 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
unregisterNotifHandler()
Unregisters the current notification handler.

Methods inherited from class org.apache.commons.net.SocketClient

_connectAction_, connect, connect, connect, connect, connect, connect, disconnect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSoLinger, setSoTimeout, setSocketFactory, setTcpNoDelay, verifyRemote

Field Details

DEFAULT_PORT

(package private) static final int DEFAULT_PORT

Field Value:
23


TERMINAL_TYPE

protected static final int TERMINAL_TYPE
Terminal type option

Field Value:
24


TERMINAL_TYPE_IS

protected static final int TERMINAL_TYPE_IS
Is (for subnegotiation)

Field Value:
0


TERMINAL_TYPE_SEND

protected static final int TERMINAL_TYPE_SEND
Send (for subnegotiation)

Field Value:
1


_COMMAND_AYT

(package private) static final byte[] _COMMAND_AYT
AYT sequence


_COMMAND_DO

(package private) static final byte[] _COMMAND_DO


_COMMAND_DONT

(package private) static final byte[] _COMMAND_DONT


_COMMAND_IS

(package private) static final byte[] _COMMAND_IS
Is sequence (for subnegotiation)


_COMMAND_SB

(package private) static final byte[] _COMMAND_SB


_COMMAND_SE

(package private) static final byte[] _COMMAND_SE


_COMMAND_WILL

(package private) static final byte[] _COMMAND_WILL


_COMMAND_WONT

(package private) static final byte[] _COMMAND_WONT


_DO_MASK

(package private) static final int _DO_MASK

Field Value:
2


_REQUESTED_DO_MASK

(package private) static final int _REQUESTED_DO_MASK

Field Value:
8


_REQUESTED_WILL_MASK

(package private) static final int _REQUESTED_WILL_MASK

Field Value:
4


_WILL_MASK

(package private) static final int _WILL_MASK

Field Value:
1


__notifhand

private TelnetNotificationHandler __notifhand
The notification handler


_doResponse

(package private)  int[] _doResponse


_options

(package private)  int[] _options


_willResponse

(package private)  int[] _willResponse


aytFlag

private boolean aytFlag
flag for AYT


aytMonitor

private Object aytMonitor
monitor to wait for AYT


debug

(package private) static final boolean debug

Field Value:
false


debugoptions

(package private) static final boolean debugoptions

Field Value:
false


optionHandlers

private TelnetOptionHandler[] optionHandlers
Array of option handlers


spyStream

private OutputStream spyStream
The stream on which to spy


terminalType

private String terminalType
Terminal type

Constructor Details

Telnet

(package private)  Telnet()
Empty Constructor


Telnet

(package private)  Telnet(String termtype)
This constructor lets you specify the terminal type.

Parameters:
termtype - - terminal type to be negotiated (ej. VT100)

Method Details

_connectAction_

protected void _connectAction_()
            throws IOException
Called upon connection.

Overrides:
_connectAction_ in interface SocketClient


_processAYTResponse

(package private) final void _processAYTResponse()
Processes the response of an AYT


_processDo

(package private)  void _processDo(int option)
            throws IOException
Processes a DO request.

Parameters:
option - - option code to be set.


_processDont

(package private)  void _processDont(int option)
            throws IOException
Processes a DONT request.

Parameters:
option - - option code to be set.


_processSuboption

(package private)  void _processSuboption(suboption[] ,
                                          int suboptionLength)
            throws IOException
Processes a suboption negotiation.

Parameters:
suboptionLength - - length of data received


_processWill

(package private)  void _processWill(int option)
            throws IOException
Processes a WILL request.

Parameters:
option - - option code to be set.


_processWont

(package private)  void _processWont(int option)
            throws IOException
Processes a WONT request.

Parameters:
option - - option code to be set.


_registerSpyStream

(package private)  void _registerSpyStream(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.


_requestDo

(package private) final void _requestDo(int option)
            throws IOException
Requests a DO.

Parameters:
option - - Option code.


_requestDont

(package private) final void _requestDont(int option)
            throws IOException
Requests a DONT.

Parameters:
option - - Option code.


_requestWill

(package private) final void _requestWill(int option)
            throws IOException
Requests a WILL.

Parameters:
option - - Option code.


_requestWont

(package private) final void _requestWont(int option)
            throws IOException
Requests a WONT.

Parameters:
option - - Option code.


_requestedDo

(package private)  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

(package private)  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

(package private)  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

(package private)  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


_sendAYT

(package private) 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


_sendByte

(package private) final void _sendByte(int b)
            throws IOException
Sends a byte.

Parameters:
b - - byte to send


_sendDo

(package private) final void _sendDo(int option)
            throws IOException
Sends a DO.

Parameters:
option - - Option code.


_sendDont

(package private) final void _sendDont(int option)
            throws IOException
Sends a DONT.

Parameters:
option - - Option code.


_sendSubnegotiation

(package private) final void _sendSubnegotiation(subn[] )
            throws IOException
Manages subnegotiation for Terminal Type.

Parameters:


_sendTerminalType

(package private) final void _sendTerminalType()
            throws IOException
Sends terminal type information.


_sendWill

(package private) final void _sendWill(int option)
            throws IOException
Sends a WILL.

Parameters:
option - - Option code.


_sendWont

(package private) final void _sendWont(int option)
            throws IOException
Sends a WONT.

Parameters:
option - - Option code.


_setDo

(package private)  void _setDo(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setDont

(package private)  void _setDont(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWantDo

(package private)  void _setWantDo(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWantDont

(package private)  void _setWantDont(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWantWill

(package private)  void _setWantWill(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWantWont

(package private)  void _setWantWont(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWill

(package private)  void _setWill(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_setWont

(package private)  void _setWont(int option)
Sets the state of the option.

Parameters:
option - - option code to be set.


_spyRead

(package private)  void _spyRead(int ch)
Sends a read char on the spy stream.

Parameters:
ch - - character read from the session


_spyWrite

(package private)  void _spyWrite(int ch)
Sends a written char on the spy stream.

Parameters:
ch - - character written to the session


_stateIsDo

(package private)  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

(package private)  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

(package private)  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

(package private)  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


_stopSpyStream

(package private)  void _stopSpyStream()
Stops spying this Telnet.


addOptionHandler

(package private)  void addOptionHandler(TelnetOptionHandler opthand)
            throws InvalidTelnetOptionException
Registers a new TelnetOptionHandler for this telnet to use.

Parameters:
opthand - - option handler to be registered.

Throws:
InvalidTelnetOptionException - - The option code is invalid.


deleteOptionHandler

(package private)  void deleteOptionHandler(int optcode)
            throws InvalidTelnetOptionException
Unregisters a TelnetOptionHandler.

Parameters:
optcode - - Code of the option to be unregistered.

Throws:
InvalidTelnetOptionException - - The option code is invalid.


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.