public class TelnetProtocol
extends java.lang.Thread
IMPORTANT: Understanding this code requires understanding the TELNET protocol and TELNET option processing, as defined in the RFCs listed below.
Modifier and Type | Field and Description |
---|---|
protected static int |
BUFFER_SIZE
Size of buffer for processing data received from remote endpoint.
|
protected java.io.OutputStream |
clientOutputStream
This field holds a reference to an
OutputStream object used to
send data to the client. |
protected int |
height
This field holds the height of the Terminal screen in rows.
|
protected boolean |
ignoreSubnegotiation
This field is true if an error occurs while processing a subnegotiation
command.
|
protected java.nio.channels.ReadableByteChannel |
inputChannel
This field holds a reference to an
ReadableByteChannel object used to
receive data from the remote endpoint. |
protected boolean |
localEcho
UNDER CONSTRUCTION
|
protected org.eclipse.remote.telnet.core.TelnetOption[] |
localOptions
An array of TelnetOption objects representing the local endpoint's TELNET
options.
|
protected int |
nextSubnegotiationByteIndex
This field holds the index into array
receivedSubnegotiation of
the next unused byte. |
protected byte[] |
processedBytes
Holds incoming network data after the TELNET protocol bytes have been
processed and removed.
|
protected java.lang.StringBuffer |
processedStringBuffer
This field holds a StringBuffer containing text recently received from
the remote endpoint (after all TELNET protocol bytes have been processed
and removed).
|
protected java.nio.ByteBuffer |
rawBytes
Holds raw bytes received from the remote endpoint, prior to any TELNET
protocol processing.
|
protected byte[] |
receivedSubnegotiation
An array of bytes that holds the TELNET subnegotiation command most
recently received from the remote endpoint.
|
protected boolean |
remoteIsTelnetServer
This field is true if the remote endpoint is a TELNET server, false if
not.
|
protected org.eclipse.remote.telnet.core.TelnetOption[] |
remoteOptions
An array of TelnetOption objects representing the remote endpoint's
TELNET options.
|
protected java.io.OutputStream |
serverOutputStream
This field holds a reference to an
OutputStream object used to
send data to the remote endpoint. |
protected TelnetCommandShell |
shell
This field holds a reference to the
TelnetCommandShell . |
protected java.net.Socket |
socket
This method holds the Socket object for the TELNET connection.
|
protected static int |
STATE_DO_RECEIVED
TELNET connection state: Last byte processed was DO code.
|
protected static int |
STATE_DONT_RECEIVED
TELNET connection state: Last byte processed was DONT code.
|
protected static int |
STATE_IAC_RECEIVED
TELNET connection state: Last byte processed was IAC code.
|
protected static int |
STATE_INITIAL
TELNET connection state: Initial state.
|
protected static int |
STATE_RECEIVING_SUBNEGOTIATION
TELNET connection state: Currently receiving sub-negotiation data.
|
protected static int |
STATE_SUBNEGOTIATION_STARTED
TELNET connection state: Last byte processed was SB.
|
protected static int |
STATE_WILL_RECEIVED
TELNET connection state: Last byte processed was WILL code.
|
protected static int |
STATE_WONT_RECEIVED
TELNET connection state: Last byte processed was WONT code.
|
static byte |
TELNET_AO
Command code: Abort Output.
|
static byte |
TELNET_AYT
Command code: Are You There.
|
static byte |
TELNET_BREAK
Command code: Break.
|
static byte |
TELNET_DM
Command code: Data Mark.
|
static byte |
TELNET_DO
Command code: Do.
|
static byte |
TELNET_DONT
Command code: Don't.
|
static byte |
TELNET_EC
Command code: Erase Character.
|
static byte |
TELNET_EL
Command code: Erase Line.
|
static byte |
TELNET_GA
Command code: Go Ahead.
|
static byte |
TELNET_IAC
Command code: Interpret As Command.
|
static byte |
TELNET_IP
Command code: Interrupt Process.
|
static byte |
TELNET_IS
Command code: IS.
|
static byte |
TELNET_NOP
Command code: No-op.
|
static byte |
TELNET_OPTION_ECHO
Option code: Echo option.
|
static byte |
TELNET_OPTION_NAWS
Option code: Negotitate About Window Size (NAWS)
|
static byte |
TELNET_OPTION_SUPPRESS_GA
Option code: Suppress Go Ahead option.
|
static byte |
TELNET_OPTION_TERMINAL_TYPE
Option code: Terminal Type
|
static byte |
TELNET_OPTION_TRANSMIT_BINARY
Option code: Transmit Binary option.
|
static byte |
TELNET_SB
Command code: Subnegotiation Begin.
|
static byte |
TELNET_SE
Command code: Subnegotiation End.
|
static byte |
TELNET_SEND
Command code: SEND.
|
static byte |
TELNET_WILL
Command code: Will.
|
static byte |
TELNET_WONT
Command code: Won't.
|
protected int |
telnetState
Holds the current state of the TELNET protocol processor.
|
protected int |
width
This field holds the width of the Terminal screen in columns.
|
Constructor and Description |
---|
TelnetProtocol(java.net.Socket socket,
TelnetCommandShell shell)
This constructor just initializes some internal object state from its
arguments.
|
Modifier and Type | Method and Description |
---|---|
java.io.OutputStream |
getOutputStream() |
protected void |
initializeOptions()
This method initializes the localOptions[] and remoteOptions[] arrays so
that they contain references to TelnetOption objects representing our
desired state for each option.
|
boolean |
isConnected()
Returns true if the TCP connection represented by this object is
connected, false otherwise.
|
boolean |
isRemoteTelnetServer()
Returns true if the TCP connection represented by this object is
connected and the remote endpoint is a TELNET server, false otherwise.
|
boolean |
localEcho()
Returns true if local echoing is enabled for this TCP connection, false
otherwise.
|
protected int |
processTelnetProtocol(int count)
Process TELNET protocol data contained in the first count bytes
of rawBytes.
|
void |
run()
This method runs in its own thread.
|
void |
setClientOutputStream(java.io.OutputStream stream) |
void |
setTerminalSize(int newWidth,
int newHeight)
This method sets the terminal width and height to the supplied values.
|
protected void |
telnetServerDetected()
This method is called whenever we receive a valid TELNET protocol command
from the remote endpoint.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
protected static final int STATE_INITIAL
protected static final int STATE_IAC_RECEIVED
protected static final int STATE_WILL_RECEIVED
protected static final int STATE_WONT_RECEIVED
protected static final int STATE_DO_RECEIVED
protected static final int STATE_DONT_RECEIVED
protected static final int STATE_SUBNEGOTIATION_STARTED
protected static final int STATE_RECEIVING_SUBNEGOTIATION
protected static final int BUFFER_SIZE
protected java.nio.ByteBuffer rawBytes
protected byte[] processedBytes
protected java.lang.StringBuffer processedStringBuffer
protected int telnetState
protected boolean remoteIsTelnetServer
When this field first changes from false to true, we send all WILL or DO commands to the remote endpoint.
telnetServerDetected()
protected org.eclipse.remote.telnet.core.TelnetOption[] localOptions
protected org.eclipse.remote.telnet.core.TelnetOption[] remoteOptions
protected byte[] receivedSubnegotiation
protected int nextSubnegotiationByteIndex
receivedSubnegotiation
of
the next unused byte. This is used by method
processTelnetProtocol(int)
when the state machine is in states
STATE_SUBNEGOTIATION_STARTED
and STATE_RECEIVING_SUBNEGOTIATION
.protected boolean ignoreSubnegotiation
processTelnetProtocol(int)
protected int width
protected int height
protected TelnetCommandShell shell
TelnetCommandShell
.protected java.net.Socket socket
protected java.nio.channels.ReadableByteChannel inputChannel
ReadableByteChannel
object used to
receive data from the remote endpoint.protected java.io.OutputStream serverOutputStream
OutputStream
object used to
send data to the remote endpoint.protected java.io.OutputStream clientOutputStream
OutputStream
object used to
send data to the client.protected boolean localEcho
public static final byte TELNET_SE
public static final byte TELNET_NOP
public static final byte TELNET_DM
public static final byte TELNET_BREAK
public static final byte TELNET_IP
public static final byte TELNET_AO
public static final byte TELNET_AYT
public static final byte TELNET_EC
public static final byte TELNET_EL
public static final byte TELNET_GA
public static final byte TELNET_SB
public static final byte TELNET_WILL
public static final byte TELNET_WONT
public static final byte TELNET_DO
public static final byte TELNET_DONT
public static final byte TELNET_IAC
public static final byte TELNET_IS
public static final byte TELNET_SEND
public static final byte TELNET_OPTION_TRANSMIT_BINARY
public static final byte TELNET_OPTION_ECHO
public static final byte TELNET_OPTION_SUPPRESS_GA
public static final byte TELNET_OPTION_TERMINAL_TYPE
public static final byte TELNET_OPTION_NAWS
public TelnetProtocol(java.net.Socket socket, TelnetCommandShell shell) throws java.io.IOException
java.io.IOException
public java.io.OutputStream getOutputStream()
public void setClientOutputStream(java.io.OutputStream stream)
public boolean isConnected()
public boolean isRemoteTelnetServer()
public void setTerminalSize(int newWidth, int newHeight)
public boolean localEcho()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected void initializeOptions()
protected int processTelnetProtocol(int count)
protected void telnetServerDetected()
This method does not negotiate options that we do not desire to be enabled, because all options are initially disabled.