org.apache.commons.net.telnet
Class TelnetClient
Telnet
org.apache.commons.net.telnet.TelnetClient
public class TelnetClient
extends Telnet
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.
InputStream | getInputStream() -
Returns the telnet connection input stream.
|
boolean | getLocalOptionState(int option) -
Returns the state of the option on the local side.
|
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 | registerSpyStream(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.
|
protected @Override | void _connectAction_() -
Handles special connection requirements.
|
@Override | void addOptionHandler(TelnetOptionHandler opthand) -
Registers a new TelnetOptionHandler for this telnet client to use.
|
@Override | void deleteOptionHandler(int optcode) -
Unregisters a TelnetOptionHandler.
|
@Override | void disconnect() -
Disconnects the telnet session, closing the input and output streams
as well as the socket.
|
@Override | void registerNotifHandler(TelnetNotificationHandler notifhand) -
Registers a notification handler to which will be sent
notifications of received telnet option negotiation commands.
|
@Override | void unregisterNotifHandler() -
Unregisters the current notification handler.
|
readerThread
protected boolean readerThread
TelnetClient
public TelnetClient()
Default TelnetClient constructor.
TelnetClient
public TelnetClient(String termtype)
getInputStream
public InputStream getInputStream()
Returns the telnet connection input stream. You should not close the
stream when you finish with it. Rather, you should call
disconnect
.
- The telnet connection input stream.
getLocalOptionState
public boolean getLocalOptionState(int option)
Returns the state of the option on the local side.
option
- - Option to be checked.
- The state of the option on the local side.
getOutputStream
public OutputStream getOutputStream()
Returns the telnet connection output stream. You should not close the
stream when you finish with it. Rather, you should call
disconnect
.
- The telnet connection output stream.
getReaderThread
public boolean getReaderThread()
Gets the status of the reader thread.
- true if the reader thread is on, false otherwise
getRemoteOptionState
public boolean getRemoteOptionState(int option)
Returns the state of the option on the remote side.
option
- - Option to be checked.
- The state of the option on the remote side.
registerSpyStream
public void registerSpyStream(OutputStream spystream)
Registers an OutputStream for spying what's going on in
the TelnetClient session.
spystream
- - OutputStream on which session activity
will be echoed.
sendAYT
public boolean sendAYT(long timeout)
throws IOException,
IllegalArgumentException,
InterruptedException
Sends an Are You There sequence and waits for the result.
timeout
- - Time to wait for a response (millis.)
- true if AYT received a response, false otherwise
setReaderThread
public void setReaderThread(boolean flag)
Sets the status of the reader thread.
The reader thread status will apply to all subsequent connections
flag
- - true switches the reader thread on, false switches it off
stopSpyStream
public void stopSpyStream()
Stops spying this TelnetClient.
void _connectAction_
protected @Override void _connectAction_()
throws IOException
Handles special connection requirements.
void addOptionHandler
public @Override void addOptionHandler(TelnetOptionHandler opthand)
throws InvalidTelnetOptionException
Registers a new TelnetOptionHandler for this telnet client to use.
opthand
- - option handler to be registered.
void deleteOptionHandler
public @Override void deleteOptionHandler(int optcode)
throws InvalidTelnetOptionException
Unregisters a TelnetOptionHandler.
optcode
- - Code of the option to be unregistered.
void disconnect
public @Override void disconnect()
throws IOException
Disconnects the telnet session, closing the input and output streams
as well as the socket. If you have references to the
input and output streams of the telnet connection, you should not
close them yourself, but rather call disconnect to properly close
the connection.
void registerNotifHandler
public @Override void registerNotifHandler(TelnetNotificationHandler notifhand)
Registers a notification handler to which will be sent
notifications of received telnet option negotiation commands.
notifhand
- - TelnetNotificationHandler to be registered
void unregisterNotifHandler
public @Override void unregisterNotifHandler()
Unregisters the current notification handler.