|
||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.commons.net.SocketClient | +--org.apache.commons.net.telnet.Telnet | +--org.apache.commons.net.telnet.TelnetClient
The TelnetClient class implements the simple network virtual terminal (NVT) for the Telnet protocol according to RFC 854. It does not implement any of the extra Telnet options because it is meant to be used within a Java program providing automated access to Telnet accessible resources.
The class can be used by first connecting to a server using the SocketClient connect method. Then an InputStream and OutputStream for sending and receiving data over the Telnet connection can be obtained by using the getInputStream() and getOutputStream() methods. When you finish using the streams, you must call disconnect rather than simply closing the streams.
Field Summary | |
---|---|
private java.io.InputStream |
__input
|
private java.io.OutputStream |
__output
|
(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) 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[] |
_willResponse
|
(package private) static boolean |
debug
|
(package private) static boolean |
debugoptions
|
(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) |
Fields inherited from class org.apache.commons.net.SocketClient |
---|
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL |
Constructor Summary | |
---|---|
TelnetClient()
Default TelnetClient constructor. |
|
TelnetClient(java.lang.String termtype)
|
Method Summary | |
---|---|
(package private) void |
_closeOutputStream()
|
protected void |
_connectAction_()
Handles special connection requirements. |
(package private) void |
_flushOutputStream()
|
(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(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 |
_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. |
void |
addOptionHandler(TelnetOptionHandler opthand)
Registers a new TelnetOptionHandler for this telnet client to use. |
void |
deleteOptionHandler(int optcode)
Unregisters a TelnetOptionHandler. |
void |
disconnect()
Disconnects the telnet session, closing the input and output streams as well as the socket. |
java.io.InputStream |
getInputStream()
Returns the telnet connection input stream. |
boolean |
getLocalOptionState(int option)
Returns the state of the option on the local side. |
java.io.OutputStream |
getOutputStream()
Returns the telnet connection output stream. |
boolean |
getRemoteOptionState(int option)
Returns the state of the option on the remote side. |
void |
registerNotifHandler(TelnetNotificationHandler notifhand)
Registers a notification handler to which will be sent notifications of received telnet option negotiation commands. |
void |
registerSpyStream(java.io.OutputStream spystream)
Registers an OutputStream for spying what's going on in the TelnetClient session. |
boolean |
sendAYT(long timeout)
Sends an Are You There sequence and waits for the result |
void |
stopSpyStream()
Stops spying this TelnetClient. |
void |
unregisterNotifHandler()
Unregisters the current notification handler. |
Methods inherited from class org.apache.commons.net.SocketClient |
---|
connect, connect, connect, connect, connect, connect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private java.io.InputStream __input
private java.io.OutputStream __output
static final boolean debug
static final boolean debugoptions
static final byte[] _COMMAND_DO
static final byte[] _COMMAND_DONT
static final byte[] _COMMAND_WILL
static final byte[] _COMMAND_WONT
static final byte[] _COMMAND_SB
static final byte[] _COMMAND_SE
static final int _WILL_MASK
static final int _DO_MASK
static final int _REQUESTED_WILL_MASK
static final int _REQUESTED_DO_MASK
static final int DEFAULT_PORT
int[] _doResponse
int[] _willResponse
int[] _options
protected static final int TERMINAL_TYPE
protected static final int TERMINAL_TYPE_SEND
protected static final int TERMINAL_TYPE_IS
static final byte[] _COMMAND_IS
static final byte[] _COMMAND_AYT
Constructor Detail |
public TelnetClient()
public TelnetClient(java.lang.String termtype)
Method Detail |
void _flushOutputStream() throws java.io.IOException
java.io.IOException
void _closeOutputStream() throws java.io.IOException
java.io.IOException
protected void _connectAction_() throws java.io.IOException
_connectAction_
in class Telnet
java.io.IOException
- If an error occurs during connection setup.public void disconnect() throws java.io.IOException
disconnect
in class SocketClient
java.io.IOException
- If there is an error closing the socket.public java.io.OutputStream getOutputStream()
public java.io.InputStream getInputStream()
public boolean getLocalOptionState(int option)
option
- - Option to be checked.
public boolean getRemoteOptionState(int option)
option
- - Option to be checked.
public boolean sendAYT(long timeout) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.InterruptedException
timeout
- - Time to wait for a response (millis.)
java.lang.InterruptedException
java.lang.IllegalArgumentException
java.io.IOException
- public void addOptionHandler(TelnetOptionHandler opthand) throws InvalidTelnetOptionException
addOptionHandler
in class Telnet
opthand
- - option handler to be registered.
InvalidTelnetOptionException
- public void deleteOptionHandler(int optcode) throws InvalidTelnetOptionException
deleteOptionHandler
in class Telnet
optcode
- - Code of the option to be unregistered.
InvalidTelnetOptionException
- public void registerSpyStream(java.io.OutputStream spystream)
spystream
- - OutputStream on which session activity
will be echoed.public void stopSpyStream()
public void registerNotifHandler(TelnetNotificationHandler notifhand)
registerNotifHandler
in class Telnet
notifhand
- - TelnetNotificationHandler to be registeredpublic void unregisterNotifHandler()
unregisterNotifHandler
in class Telnet
boolean _stateIsWill(int option)
option
- - option code to be looked up.
boolean _stateIsWont(int option)
option
- - option code to be looked up.
boolean _stateIsDo(int option)
option
- - option code to be looked up.
boolean _stateIsDont(int option)
option
- - option code to be looked up.
boolean _requestedWill(int option)
option
- - option code to be looked up.
boolean _requestedWont(int option)
option
- - option code to be looked up.
boolean _requestedDo(int option)
option
- - option code to be looked up.
boolean _requestedDont(int option)
option
- - option code to be looked up.
void _setWill(int option)
option
- - option code to be set.void _setDo(int option)
option
- - option code to be set.void _setWantWill(int option)
option
- - option code to be set.void _setWantDo(int option)
option
- - option code to be set.void _setWont(int option)
option
- - option code to be set.void _setDont(int option)
option
- - option code to be set.void _setWantWont(int option)
option
- - option code to be set.void _setWantDont(int option)
option
- - option code to be set.void _processDo(int option) throws java.io.IOException
option
- - option code to be set.
java.io.IOException
- - Exception in I/O.
void _processDont(int option) throws java.io.IOException
option
- - option code to be set.
java.io.IOException
- - Exception in I/O.
void _processWill(int option) throws java.io.IOException
option
- - option code to be set.
java.io.IOException
- - Exception in I/O.
void _processWont(int option) throws java.io.IOException
option
- - option code to be set.
java.io.IOException
- - Exception in I/O.
void _processSuboption(int[] suboption, int suboptionLength) throws java.io.IOException
suboption
- - subnegotiation data receivedsuboptionLength
- - length of data received
java.io.IOException
- - Exception in I/O.
final void _sendTerminalType() throws java.io.IOException
java.io.IOException
- - Exception in I/O.final void _sendSubnegotiation(int[] subn) throws java.io.IOException
subn
- - subnegotiation data to be sent
java.io.IOException
- - Exception in I/O.
final void _processAYTResponse()
final void _sendDo(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _requestDo(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _sendDont(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _requestDont(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _sendWill(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _requestWill(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _sendWont(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _requestWont(int option) throws java.io.IOException
option
- - Option code.
java.io.IOException
- - Exception in I/O.
final void _sendByte(int b) throws java.io.IOException
b
- - byte to send
java.io.IOException
- - Exception in I/O.
final boolean _sendAYT(long timeout) throws java.io.IOException, java.lang.IllegalArgumentException, java.lang.InterruptedException
timeout
- - Time to wait for a response (millis.)
java.io.IOException
- - Exception in I/O.
java.lang.IllegalArgumentException
- - Illegal argument
java.lang.InterruptedException
- - Interrupted during wait.
void _registerSpyStream(java.io.OutputStream spystream)
spystream
- - OutputStream on which session activity
will be echoed.void _stopSpyStream()
void _spyRead(int ch)
ch
- - character read from the sessionvoid _spyWrite(int ch)
ch
- - character written to the session
|
||||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |