org.apache.commons.net.telnet
Class TelnetClient

java.lang.Object
  extended byorg.apache.commons.net.SocketClient
      extended byorg.apache.commons.net.telnet.Telnet
          extended byorg.apache.commons.net.telnet.TelnetClient
Direct Known Subclasses:
FTP

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

Field Summary
private  java.io.InputStream __input
           
private  java.io.OutputStream __output
           
(package private) static byte[] _COMMAND_DO
           
(package private) static byte[] _COMMAND_DONT
           
(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 int DEFAULT_PORT
           
 
Fields inherited from class org.apache.commons.net.SocketClient
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL
 
Constructor Summary
TelnetClient()
          Default TelnetClient constructor.
 
Method Summary
(package private)  void _closeOutputStream()
           
protected  void _connectAction_()
          Handles special connection requirements.
(package private)  void _flushOutputStream()
           
(package private)  void _processDo(int option)
           
(package private)  void _processDont(int option)
           
(package private)  void _processWill(int option)
           
(package private)  void _processWont(int option)
           
(package private)  void _requestDo(int option)
           
(package private)  void _requestDont(int option)
           
(package private)  boolean _requestedDo(int option)
           
(package private)  boolean _requestedDont(int option)
           
(package private)  boolean _requestedWill(int option)
           
(package private)  boolean _requestedWont(int option)
           
(package private)  void _requestWill(int option)
           
(package private)  void _requestWont(int option)
           
(package private)  void _sendByte(int b)
           
(package private)  void _sendDo(int option)
           
(package private)  void _sendDont(int option)
           
(package private)  void _sendWill(int option)
           
(package private)  void _sendWont(int option)
           
(package private)  void _setDo(int option)
           
(package private)  void _setDont(int option)
           
(package private)  void _setWantDo(int option)
           
(package private)  void _setWantDont(int option)
           
(package private)  void _setWantWill(int option)
           
(package private)  void _setWantWont(int option)
           
(package private)  void _setWill(int option)
           
(package private)  void _setWont(int option)
           
(package private)  boolean _stateIsDo(int option)
           
(package private)  boolean _stateIsDont(int option)
           
(package private)  boolean _stateIsWill(int option)
           
(package private)  boolean _stateIsWont(int option)
           
 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.
 java.io.OutputStream getOutputStream()
          Returns the telnet connection output stream.
 
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

__input

private java.io.InputStream __input

__output

private java.io.OutputStream __output

debug

static final boolean debug
See Also:
Constant Field Values

_COMMAND_DO

static final byte[] _COMMAND_DO

_COMMAND_DONT

static final byte[] _COMMAND_DONT

_COMMAND_WILL

static final byte[] _COMMAND_WILL

_COMMAND_WONT

static final byte[] _COMMAND_WONT

_COMMAND_SB

static final byte[] _COMMAND_SB

_COMMAND_SE

static final byte[] _COMMAND_SE

_WILL_MASK

static final int _WILL_MASK
See Also:
Constant Field Values

_DO_MASK

static final int _DO_MASK
See Also:
Constant Field Values

_REQUESTED_WILL_MASK

static final int _REQUESTED_WILL_MASK
See Also:
Constant Field Values

_REQUESTED_DO_MASK

static final int _REQUESTED_DO_MASK
See Also:
Constant Field Values

DEFAULT_PORT

static final int DEFAULT_PORT
See Also:
Constant Field Values

_doResponse

int[] _doResponse

_willResponse

int[] _willResponse

_options

int[] _options
Constructor Detail

TelnetClient

public TelnetClient()
Default TelnetClient constructor.

Method Detail

_flushOutputStream

void _flushOutputStream()
                  throws java.io.IOException
Throws:
java.io.IOException

_closeOutputStream

void _closeOutputStream()
                  throws java.io.IOException
Throws:
java.io.IOException

_connectAction_

protected void _connectAction_()
                        throws java.io.IOException
Handles special connection requirements.

Overrides:
_connectAction_ in class Telnet
Throws:
java.io.IOException - If an error occurs during connection setup.

disconnect

public void disconnect()
                throws java.io.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.

Overrides:
disconnect in class SocketClient
Throws:
java.io.IOException - If there is an error closing the socket.

getOutputStream

public java.io.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.

getInputStream

public java.io.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.

_stateIsWill

boolean _stateIsWill(int option)

_stateIsWont

boolean _stateIsWont(int option)

_stateIsDo

boolean _stateIsDo(int option)

_stateIsDont

boolean _stateIsDont(int option)

_requestedWill

boolean _requestedWill(int option)

_requestedWont

boolean _requestedWont(int option)

_requestedDo

boolean _requestedDo(int option)

_requestedDont

boolean _requestedDont(int option)

_setWill

void _setWill(int option)

_setDo

void _setDo(int option)

_setWantWill

void _setWantWill(int option)

_setWantDo

void _setWantDo(int option)

_setWont

void _setWont(int option)

_setDont

void _setDont(int option)

_setWantWont

void _setWantWont(int option)

_setWantDont

void _setWantDont(int option)

_processDo

void _processDo(int option)
          throws java.io.IOException
Throws:
java.io.IOException

_processDont

void _processDont(int option)
            throws java.io.IOException
Throws:
java.io.IOException

_processWill

void _processWill(int option)
            throws java.io.IOException
Throws:
java.io.IOException

_processWont

void _processWont(int option)
            throws java.io.IOException
Throws:
java.io.IOException

_sendDo

final void _sendDo(int option)
            throws java.io.IOException
Throws:
java.io.IOException

_requestDo

final void _requestDo(int option)
               throws java.io.IOException
Throws:
java.io.IOException

_sendDont

final void _sendDont(int option)
              throws java.io.IOException
Throws:
java.io.IOException

_requestDont

final void _requestDont(int option)
                 throws java.io.IOException
Throws:
java.io.IOException

_sendWill

final void _sendWill(int option)
              throws java.io.IOException
Throws:
java.io.IOException

_requestWill

final void _requestWill(int option)
                 throws java.io.IOException
Throws:
java.io.IOException

_sendWont

final void _sendWont(int option)
              throws java.io.IOException
Throws:
java.io.IOException

_requestWont

final void _requestWont(int option)
                 throws java.io.IOException
Throws:
java.io.IOException

_sendByte

final void _sendByte(int b)
              throws java.io.IOException
Throws:
java.io.IOException