public class TelnetClient extends SocketClient
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.
Modifier and Type | Field and Description |
---|---|
protected boolean |
readerThread |
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)
|
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL
Constructor and Description |
---|
TelnetClient()
Default TelnetClient constructor.
|
TelnetClient(java.lang.String termtype) |
Modifier and Type | Method and Description |
---|---|
protected void |
_connectAction_()
Handles special connection requirements.
|
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 |
getReaderThread()
Gets the status of the reader thread.
|
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 |
setReaderThread(boolean flag)
Sets the status of the reader thread.
|
void |
stopSpyStream()
Stops spying this TelnetClient.
|
void |
unregisterNotifHandler()
Unregisters the current notification handler.
|
connect, connect, connect, connect, connect, connect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
protected boolean readerThread
protected static final int TERMINAL_TYPE
protected static final int TERMINAL_TYPE_SEND
protected static final int TERMINAL_TYPE_IS
public TelnetClient()
public TelnetClient(java.lang.String termtype)
protected void _connectAction_() throws java.io.IOException
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()
disconnect
.
public java.io.InputStream getInputStream()
disconnect
.
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
opthand
- - option handler to be registered.InvalidTelnetOptionException
- public void deleteOptionHandler(int optcode) throws InvalidTelnetOptionException
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)
notifhand
- - TelnetNotificationHandler to be registeredpublic void unregisterNotifHandler()
public void setReaderThread(boolean flag)
flag
- - true switches the reader thread on, false switches it offpublic boolean getReaderThread()