FileDocCategorySizeDatePackage
TelnetClient.javaAPI DocApache Commons NET 1.4.1 API8997Sat Dec 03 10:05:48 GMT 2005org.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 {@link org.apache.commons.net.SocketClient#connect connect} method. Then an InputStream and OutputStream for sending and receiving data over the Telnet connection can be obtained by using the {@link #getInputStream getInputStream() } and {@link #getOutputStream getOutputStream() } methods. When you finish using the streams, you must call {@link #disconnect disconnect } rather than simply closing the streams.

author
Daniel F. Savarese
author
Bruno D'Avanzo

Fields Summary
private InputStream
__input
private OutputStream
__output
protected boolean
readerThread
Constructors Summary
public TelnetClient()
Default TelnetClient constructor.


            
     
    
        /* TERMINAL-TYPE option (start)*/
        super ("VT100");
        /* TERMINAL-TYPE option (end)*/
        __input = null;
        __output = null;
    
public TelnetClient(String termtype)

        super (termtype);
        __input = null;
        __output = null;
    
Methods Summary
void_closeOutputStream()

        _output_.close();
    
protected void_connectAction_()
Handles special connection requirements.

exception
IOException If an error occurs during connection setup.

        super._connectAction_();
        InputStream input;
        TelnetInputStream tmp;

        if (FromNetASCIIInputStream.isConversionRequired())
            input = new FromNetASCIIInputStream(_input_);
        else
            input = _input_;


        tmp = new TelnetInputStream(input, this, readerThread);
        if(readerThread)
        {
            tmp._start();
        }
        // __input CANNOT refer to the TelnetInputStream.  We run into
        // blocking problems when some classes use TelnetInputStream, so
        // we wrap it with a BufferedInputStream which we know is safe.
        // This blocking behavior requires further investigation, but right
        // now it looks like classes like InputStreamReader are not implemented
        // in a safe manner.
        __input = new BufferedInputStream(tmp);
        __output = new ToNetASCIIOutputStream(new TelnetOutputStream(this));
    
void_flushOutputStream()

        _output_.flush();
    
public voidaddOptionHandler(TelnetOptionHandler opthand)
Registers a new TelnetOptionHandler for this telnet client to use.

throws
InvalidTelnetOptionException

param
opthand - option handler to be registered.

        super.addOptionHandler(opthand);
    
public voiddeleteOptionHandler(int optcode)
Unregisters a TelnetOptionHandler.

throws
InvalidTelnetOptionException

param
optcode - Code of the option to be unregistered.

        super.deleteOptionHandler(optcode);
    
public voiddisconnect()
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.

        __input.close();
        __output.close();
        super.disconnect();
    
public java.io.InputStreamgetInputStream()
Returns the telnet connection input stream. You should not close the stream when you finish with it. Rather, you should call {@link #disconnect disconnect }.

return
The telnet connection input stream.

        return __input;
    
public booleangetLocalOptionState(int option)
Returns the state of the option on the local side.

param
option - Option to be checked.

return
The state of the option on the local side.

        /* BUG (option active when not already acknowledged) (start)*/
        return (_stateIsWill(option) && _requestedWill(option));
        /* BUG (option active when not already acknowledged) (end)*/
    
public java.io.OutputStreamgetOutputStream()
Returns the telnet connection output stream. You should not close the stream when you finish with it. Rather, you should call {@link #disconnect disconnect }.

return
The telnet connection output stream.

        return __output;
    
public booleangetReaderThread()
Gets the status of the reader thread.

return
true if the reader thread is on, false otherwise

        return (readerThread);
    
public booleangetRemoteOptionState(int option)
Returns the state of the option on the remote side.

param
option - Option to be checked.

return
The state of the option on the remote side.

        /* BUG (option active when not already acknowledged) (start)*/
        return (_stateIsDo(option) && _requestedDo(option));
        /* BUG (option active when not already acknowledged) (end)*/
    
public voidregisterNotifHandler(TelnetNotificationHandler notifhand)
Registers a notification handler to which will be sent notifications of received telnet option negotiation commands.

param
notifhand - TelnetNotificationHandler to be registered

        super.registerNotifHandler(notifhand);
    
public voidregisterSpyStream(java.io.OutputStream spystream)
Registers an OutputStream for spying what's going on in the TelnetClient session.

param
spystream - OutputStream on which session activity will be echoed.

        super._registerSpyStream(spystream);
    
public booleansendAYT(long timeout)
Sends an Are You There sequence and waits for the result.

throws
InterruptedException
throws
IllegalArgumentException
throws
IOException

param
timeout - Time to wait for a response (millis.)

return
true if AYT received a response, false otherwise

        return (_sendAYT(timeout));
    
public voidsetReaderThread(boolean flag)
Sets the status of the reader thread. The reader thread status will apply to all subsequent connections

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

        readerThread = flag;
    
public voidstopSpyStream()
Stops spying this TelnetClient.

        super._stopSpyStream();
    
public voidunregisterNotifHandler()
Unregisters the current notification handler.

        super.unregisterNotifHandler();