it.m2.net.telnet
Class Telnet

java.lang.Object
  extended by it.m2.net.telnet.Telnet
All Implemented Interfaces:
TelnetOptions
Direct Known Subclasses:
NVT

public class Telnet
extends java.lang.Object
implements TelnetOptions

Class to handle telnet protocol

Version:
$Id: Telnet.java,v 1.1 2009/07/15 20:40:51 bobh Exp $ Modified by Bob Herlien, MBARI. Added available(), flush(), and read(byte[],int,int) to support InputStream/OutputStream
Author:
Mario Viara

Field Summary
protected  java.net.Socket socket
           
 
Fields inherited from interface it.m2.net.telnet.TelnetOptions
COM_PORT_OPTION, CR, DATASIZE5, DATASIZE6, DATASIZE7, DATASIZE8, DO, DONT, ECHO, FLOW_CTRL_DCD, FLOW_CTRL_DSR, FLOW_CTRL_DTR, FLOW_CTRL_IN_HARDWARE, FLOW_CTRL_IN_NONE, FLOW_CTRL_IN_XONXOFF, FLOWCONTROL_RESUME, FLOWCONTROL_SUSPEND, IAC, LF, MODEM_CTS, MODEM_DCD, MODEM_DCTS, MODEM_DDCD, MODEM_DDSR, MODEM_DRI, MODEM_DSR, MODEM_RI, NOP, NOTIFY_LINESTATE, NOTIFY_MODEMSTATE, PARITY_EVEN, PARITY_MARK, PARITY_NONE, PARITY_ODD, PARITY_SPACE, PURGE_DATA, REQUEST_INBOUND, SB, SE, SERVER_PREFIX, SET_BAUDRATE, SET_CONTROL, SET_DATASIZE, SET_LINESTATE_MASK, SET_MODEMSTATE_MASK, SET_PARITY, SET_STOPSIZE, SIGNATURE, STOP_1, STOP_15, STOP_2, SUPPRESS_GO_AHEAD, TERMINAL_TYPE, TERMINAL_TYPE_IS, TERMINAL_TYPE_SEND, TRASMIT_BINARY, WILL, WONT
 
Constructor Summary
Telnet()
           
Telnet(java.net.Socket socket)
           
Telnet(java.lang.String host, int port)
           
 
Method Summary
static void addLogger(java.io.OutputStream os)
           
static void addLogger(java.lang.String filename)
           
static void addLogger(TelnetLogger logger)
           
 void addOption(int option, it.m2.net.telnet.TelnetOptionHandler handler)
           
 int available()
          Return number of bytes that can be read from RingBuffer.
 void close()
           
 void flush()
          Flush the OutputStream Added to support NVTOutputStream.flush()
 java.net.InetAddress getInetAddress()
           
 boolean getLocalOption(int option)
           
 int getLogLevel()
           
 long getReceivedByteCount()
           
 java.lang.String getRemoteHost()
           
 boolean getRemoteOption(int option)
           
 int getRemotePort()
           
 long getSentByteCount()
           
 boolean isDo(int option)
           
 boolean isLog(int level)
           
 boolean isWill(int option)
           
 void log(int level, java.lang.String txt)
           
 void log(int lvl, java.lang.String title, byte[] buffer, int length)
           
static void main(java.lang.String[] args)
           
 boolean negotiate()
           
 int read()
           
 int read(byte[] buffer)
           
 int read(byte[] buffer, int off, int len)
           
 void releaseCpu()
           
 void sendIAC(int cmd)
           
 void sendIAC(int cmd, int opt)
           
 void sendIACNOP()
           
 void sendSB(int cmd, int opt)
           
 void sendSB(int cmd, int opt, byte[] buffer)
           
 void sendSB(int cmd, int opt, int value)
           
 void sendSB(int cmd, int opt, java.lang.String buffer)
           
protected  void setDefaults()
           
 boolean setDoOption(int option, boolean mode)
           
static void setLogLevel(int level)
           
protected  void setOptions()
           
 void setSocket(java.net.Socket socket)
           
 void setSocket(java.lang.String host, int port)
           
 boolean setWillOption(int option, boolean mode)
           
 boolean setWillOption(it.m2.net.telnet.TelnetOptionStatus option, boolean mode)
           
protected  void updateReceivedByteCount(int value)
           
protected  void updateSentByteCount(int value)
           
 void write(byte[] buffer)
           
 void write(byte[] buffer, int from, int len)
           
 void write(int c)
           
 void write(java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

protected java.net.Socket socket
Constructor Detail

Telnet

public Telnet()
       throws java.io.IOException
Throws:
java.io.IOException

Telnet

public Telnet(java.lang.String host,
              int port)
       throws java.io.IOException
Throws:
java.io.IOException

Telnet

public Telnet(java.net.Socket socket)
       throws java.io.IOException
Throws:
java.io.IOException
Method Detail

addLogger

public static void addLogger(java.io.OutputStream os)

addLogger

public static void addLogger(java.lang.String filename)

addLogger

public static void addLogger(TelnetLogger logger)

isLog

public boolean isLog(int level)

log

public void log(int lvl,
                java.lang.String title,
                byte[] buffer,
                int length)

log

public void log(int level,
                java.lang.String txt)

setSocket

public final void setSocket(java.lang.String host,
                            int port)
                     throws java.io.IOException
Throws:
java.io.IOException

setSocket

public final void setSocket(java.net.Socket socket)
                     throws java.io.IOException
Throws:
java.io.IOException

setOptions

protected void setOptions()
                   throws java.io.IOException
Throws:
java.io.IOException

setDefaults

protected void setDefaults()
                    throws java.io.IOException
Throws:
java.io.IOException

available

public int available()
Return number of bytes that can be read from RingBuffer. Added to support NVTInputStream.available().


flush

public void flush()
           throws java.io.IOException
Flush the OutputStream Added to support NVTOutputStream.flush()

Throws:
java.io.IOException

releaseCpu

public void releaseCpu()

isDo

public boolean isDo(int option)

isWill

public boolean isWill(int option)

setWillOption

public boolean setWillOption(it.m2.net.telnet.TelnetOptionStatus option,
                             boolean mode)
                      throws java.io.IOException
Throws:
java.io.IOException

setWillOption

public boolean setWillOption(int option,
                             boolean mode)
                      throws java.io.IOException
Throws:
java.io.IOException

getLocalOption

public boolean getLocalOption(int option)

getRemoteOption

public boolean getRemoteOption(int option)

addOption

public void addOption(int option,
                      it.m2.net.telnet.TelnetOptionHandler handler)

setDoOption

public boolean setDoOption(int option,
                           boolean mode)
                    throws java.io.IOException
Throws:
java.io.IOException

sendIACNOP

public void sendIACNOP()
                throws java.lang.Exception
Throws:
java.lang.Exception

sendSB

public void sendSB(int cmd,
                   int opt,
                   byte[] buffer)
            throws java.io.IOException
Throws:
java.io.IOException

sendSB

public void sendSB(int cmd,
                   int opt,
                   java.lang.String buffer)
            throws java.io.IOException
Throws:
java.io.IOException

sendSB

public void sendSB(int cmd,
                   int opt,
                   int value)
            throws java.io.IOException
Throws:
java.io.IOException

sendSB

public void sendSB(int cmd,
                   int opt)
            throws java.io.IOException
Throws:
java.io.IOException

sendIAC

public void sendIAC(int cmd)
             throws java.io.IOException
Throws:
java.io.IOException

sendIAC

public void sendIAC(int cmd,
                    int opt)
             throws java.io.IOException
Throws:
java.io.IOException

negotiate

public boolean negotiate()
                  throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] buffer,
                int off,
                int len)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read(byte[] buffer)
         throws java.io.IOException
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
Throws:
java.io.IOException

write

public void write(int c)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(java.lang.String s)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] buffer)
           throws java.io.IOException
Throws:
java.io.IOException

write

public void write(byte[] buffer,
                  int from,
                  int len)
           throws java.io.IOException
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)

updateReceivedByteCount

protected void updateReceivedByteCount(int value)

updateSentByteCount

protected void updateSentByteCount(int value)

getReceivedByteCount

public long getReceivedByteCount()

getSentByteCount

public long getSentByteCount()

setLogLevel

public static void setLogLevel(int level)

getLogLevel

public int getLogLevel()

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException

getInetAddress

public java.net.InetAddress getInetAddress()

getRemoteHost

public java.lang.String getRemoteHost()

getRemotePort

public int getRemotePort()


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.