org.apache.commons.net.telnet

Class 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.

Author: Daniel F. Savarese Bruno D'Avanzo

Field Summary
protected booleanreaderThread
Constructor Summary
TelnetClient()
Default TelnetClient constructor.
TelnetClient(String termtype)
Method Summary
InputStreamgetInputStream()
Returns the telnet connection input stream.
booleangetLocalOptionState(int option)
Returns the state of the option on the local side.
OutputStreamgetOutputStream()
Returns the telnet connection output stream.
booleangetReaderThread()
Gets the status of the reader thread.
booleangetRemoteOptionState(int option)
Returns the state of the option on the remote side.
voidregisterSpyStream(OutputStream spystream)
Registers an OutputStream for spying what's going on in the TelnetClient session.
booleansendAYT(long timeout)
Sends an Are You There sequence and waits for the result.
voidsetReaderThread(boolean flag)
Sets the status of the reader thread.
voidstopSpyStream()
Stops spying this TelnetClient.

Field Detail

readerThread

protected boolean readerThread

Constructor Detail

TelnetClient

public TelnetClient()
Default TelnetClient constructor.

TelnetClient

public TelnetClient(String termtype)

Method Detail

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 .

Returns: The telnet connection input stream.

getLocalOptionState

public boolean getLocalOptionState(int option)
Returns the state of the option on the local side.

Parameters: option - Option to be checked.

Returns: 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 .

Returns: The telnet connection output stream.

getReaderThread

public boolean getReaderThread()
Gets the status of the reader thread.

Returns: 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.

Parameters: option - Option to be checked.

Returns: 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.

Parameters: spystream - OutputStream on which session activity will be echoed.

sendAYT

public boolean sendAYT(long timeout)
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: InterruptedException IllegalArgumentException IOException

setReaderThread

public void setReaderThread(boolean flag)
Sets the status of the reader thread. The reader thread status will apply to all subsequent connections

Parameters: flag - true switches the reader thread on, false switches it off

stopSpyStream

public void stopSpyStream()
Stops spying this TelnetClient.