- java.lang.Object
-
- org.jline.builtins.telnet.TelnetIO
-
public class TelnetIO extends Object
Class that represents the TelnetIO implementation. It contains an inner IACHandler class to handle the telnet protocol level communication.Although supposed to work full-duplex, we only process the telnet protocol layer communication in case of reading requests from the higher levels. This is the only way to meet the one thread per connection requirement.
The output is done via byte-oriented streams, definately suitable for the telnet protocol. The format of the output is UTF-8 (Unicode), which is a standard and supported by any telnet client, including the ones included in Microsoft OS's.
Notes:- The underlying output is buffered, to ensure that all bytes written are send, the flush() method has to be called.
- This low-level routines ensure nice multithreading behaviour on I/O. Neither large outputs, nor input sequences excuted by the connection thread can hog the system.
- Version:
- 2.0 (16/07/2006)
- Author:
- Dieter Wimberger
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAOAbort Outputprotected static intAUTHENTICATIONprotected static intAYTAre You Thereprotected static intBRKBreakprotected static intDMData mark its the data part of a SYNCH which helps to clean up the buffers between Telnet Server <-> Telnet Client.protected static intDONegotiation: Do optionprotected static intDONTNegotiation: Dont do optionprotected static intECErase Charprotected static intECHOTelnet Option: ECHOprotected static intELErase Lineprotected static intENCRYPTprotected static intEXT_ASCIIUnusedprotected static intGAGo Ahead
Newer Telnets do not make use of this option that allows a specific communication mode.protected static intIACInterpret As Commandprotected static intIPInterrupt Processprotected static intISTTYPE subnegotiation: ISprotected static intLINEMODETelnet Option: Linemodeprotected static intLM_EDITprotected static intLM_FORWARDMASKprotected static intLM_MODEprotected static intLM_MODEACKFollowing methods implement init/request/answer procedures for telnet protocol level communication.protected static intLM_SLCprotected static intLM_SLC_ABORTThe following implement the NVT (network virtual terminal) which offers the concept of a simple "printer".protected static intLM_SLC_ACKprotected static intLM_SLC_AOprotected static intLM_SLC_AYTprotected static intLM_SLC_BRKprotected static intLM_SLC_CANTCHANGEConstants declarationprotected static intLM_SLC_DEFAULTprotected static intLM_SLC_EOFprotected static intLM_SLC_EORprotected static intLM_SLC_FLUSHINprotected static intLM_SLC_FLUSHOUTprotected static intLM_SLC_IPprotected static intLM_SLC_LEVELBITSprotected static intLM_SLC_NOSUPPORTprotected static intLM_SLC_SUSPprotected static intLM_SLC_SYNCHprotected static intLM_SLC_VALUEEnd telnet protocol level communication methodsprotected static intLM_TRAPSIGprotected static intLOGOUTTelnet Option: Logout
This allows nice goodbye to time-outed or unwanted clients.protected static intNAWSTelnet Option: Negotiate About Window Size
Server request is IAC DO NAWS Client response contains subnegotiation with data (columns, rows).protected static intNE_ESCThe following options are options for which we also support subnegotiation based upon the telnet protocol specification.protected static intNE_IN_ENDprotected static intNE_IN_ERRORprotected static intNE_INFOprotected static intNE_USERVARprotected static intNE_VALUEprotected static intNE_VARThe following are constants for supported options, which can be negotiated based upon the telnet protocol specification.protected static intNE_VAR_DEFINEDprotected static intNE_VAR_DEFINED_EMPTYprotected static intNE_VAR_NAME_MAXLENGTHprotected static intNE_VAR_OKprotected static intNE_VAR_UNDEFINEDprotected static intNE_VAR_VALUE_MAXLENGTHprotected static intNEWENVTelnet Option: Environmentprotected static intNOPNo operationprotected static intSBMarks start of a subnegotiation.protected static intSEMarks end of subnegotiation.protected static intSENDTTYPE subnegotiation: SENDprotected static intSEND_LOCprotected static intSUPGATelnet Option: SUPress Go Ahead
This will be negotiated, all new telnet protocol implementations are recommended to do this.protected static intTTYPETelnet Option: Terminal TYPE
Server request contains subnegotiation SEND Client response contains subnegotiation with data IS,terminal type stringprotected static intWILLNegotiation: Will do optionprotected static intWONTNegotiation: Wont do option
-
Constructor Summary
Constructors Constructor Description TelnetIO()Creates a TelnetIO object for the given connection.
Input- and OutputStreams are properly set and the primary telnet protocol initialization is carried out by the inner IACHandler class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcloseInput()Method to close the underlying inputstream to free system resources.
Most likely only to be called by the ConnectionManager upon clean up of connections that ended or died.voidcloseOutput()Method to close the underlying output stream to free system resources.
Most likely only to be called by the ConnectionManager upon clean up of connections that ended or died.voidflush()Method to flush all buffered output.voidinitIO()intread()Method to read a byte from the InputStream.voidsetConnection(Connection con)voidsetEcho(boolean b)voidwrite(byte b)Method to output a byte.voidwrite(byte[] sequence)Method to write an array of bytes.voidwrite(char ch)Method to write a char.voidwrite(int i)Method to output an int.voidwrite(int[] sequence)Method to output an array of int' s.voidwrite(String str)Method to output a string.
-
-
-
Field Detail
-
IAC
protected static final int IAC
Interpret As Command- See Also:
- Constant Field Values
-
GA
protected static final int GA
Go Ahead
Newer Telnets do not make use of this option that allows a specific communication mode.- See Also:
- Constant Field Values
-
WILL
protected static final int WILL
Negotiation: Will do option- See Also:
- Constant Field Values
-
WONT
protected static final int WONT
Negotiation: Wont do option- See Also:
- Constant Field Values
-
DO
protected static final int DO
Negotiation: Do option- See Also:
- Constant Field Values
-
DONT
protected static final int DONT
Negotiation: Dont do option- See Also:
- Constant Field Values
-
SB
protected static final int SB
Marks start of a subnegotiation.- See Also:
- Constant Field Values
-
SE
protected static final int SE
Marks end of subnegotiation.- See Also:
- Constant Field Values
-
NOP
protected static final int NOP
No operation- See Also:
- Constant Field Values
-
DM
protected static final int DM
Data mark its the data part of a SYNCH which helps to clean up the buffers between Telnet Server <-> Telnet Client.
It should work like this we send a TCP urgent package and <IAC> <DM> the receiver should get the urgent package (SYNCH) and just discard everything until he receives our <IAC> <DM>.
Remark:- can we send a TCP urgent package?
- can we make use of the thing at all?
- See Also:
- Constant Field Values
-
BRK
protected static final int BRK
Break- See Also:
- Constant Field Values
-
IP
protected static final int IP
Interrupt Process- See Also:
- Constant Field Values
-
AO
protected static final int AO
Abort Output- See Also:
- Constant Field Values
-
AYT
protected static final int AYT
Are You There- See Also:
- Constant Field Values
-
EC
protected static final int EC
Erase Char- See Also:
- Constant Field Values
-
EL
protected static final int EL
Erase Line- See Also:
- Constant Field Values
-
ECHO
protected static final int ECHO
Telnet Option: ECHO- See Also:
- Constant Field Values
-
SUPGA
protected static final int SUPGA
Telnet Option: SUPress Go Ahead
This will be negotiated, all new telnet protocol implementations are recommended to do this.- See Also:
- Constant Field Values
-
NAWS
protected static final int NAWS
Telnet Option: Negotiate About Window Size
- Server request is IAC DO NAWS
- Client response contains subnegotiation with data (columns, rows).
- See Also:
- Constant Field Values
-
TTYPE
protected static final int TTYPE
Telnet Option: Terminal TYPE
- Server request contains subnegotiation SEND
- Client response contains subnegotiation with data IS,terminal type string
- See Also:
- Constant Field Values
-
IS
protected static final int IS
TTYPE subnegotiation: IS- See Also:
- Constant Field Values
-
SEND
protected static final int SEND
TTYPE subnegotiation: SEND- See Also:
- Constant Field Values
-
LOGOUT
protected static final int LOGOUT
Telnet Option: Logout
This allows nice goodbye to time-outed or unwanted clients.- See Also:
- Constant Field Values
-
LINEMODE
protected static final int LINEMODE
Telnet Option: LinemodeThe infamous line mode option.
- See Also:
- Constant Field Values
-
LM_MODE
protected static final int LM_MODE
- See Also:
- Constant Field Values
-
LM_EDIT
protected static final int LM_EDIT
- See Also:
- Constant Field Values
-
LM_TRAPSIG
protected static final int LM_TRAPSIG
- See Also:
- Constant Field Values
-
LM_MODEACK
protected static final int LM_MODEACK
Following methods implement init/request/answer procedures for telnet protocol level communication.- See Also:
- Constant Field Values
-
LM_FORWARDMASK
protected static final int LM_FORWARDMASK
- See Also:
- Constant Field Values
-
LM_SLC
protected static final int LM_SLC
- See Also:
- Constant Field Values
-
LM_SLC_NOSUPPORT
protected static final int LM_SLC_NOSUPPORT
- See Also:
- Constant Field Values
-
LM_SLC_DEFAULT
protected static final int LM_SLC_DEFAULT
- See Also:
- Constant Field Values
-
LM_SLC_VALUE
protected static final int LM_SLC_VALUE
End telnet protocol level communication methods- See Also:
- Constant Field Values
-
LM_SLC_CANTCHANGE
protected static final int LM_SLC_CANTCHANGE
Constants declaration- See Also:
- Constant Field Values
-
LM_SLC_LEVELBITS
protected static final int LM_SLC_LEVELBITS
- See Also:
- Constant Field Values
-
LM_SLC_ACK
protected static final int LM_SLC_ACK
- See Also:
- Constant Field Values
-
LM_SLC_FLUSHIN
protected static final int LM_SLC_FLUSHIN
- See Also:
- Constant Field Values
-
LM_SLC_FLUSHOUT
protected static final int LM_SLC_FLUSHOUT
- See Also:
- Constant Field Values
-
LM_SLC_SYNCH
protected static final int LM_SLC_SYNCH
- See Also:
- Constant Field Values
-
LM_SLC_BRK
protected static final int LM_SLC_BRK
- See Also:
- Constant Field Values
-
LM_SLC_IP
protected static final int LM_SLC_IP
- See Also:
- Constant Field Values
-
LM_SLC_AO
protected static final int LM_SLC_AO
- See Also:
- Constant Field Values
-
LM_SLC_AYT
protected static final int LM_SLC_AYT
- See Also:
- Constant Field Values
-
LM_SLC_EOR
protected static final int LM_SLC_EOR
- See Also:
- Constant Field Values
-
LM_SLC_ABORT
protected static final int LM_SLC_ABORT
The following implement the NVT (network virtual terminal) which offers the concept of a simple "printer". They are the basical meanings of control possibilities on a standard telnet implementation.- See Also:
- Constant Field Values
-
LM_SLC_EOF
protected static final int LM_SLC_EOF
- See Also:
- Constant Field Values
-
LM_SLC_SUSP
protected static final int LM_SLC_SUSP
- See Also:
- Constant Field Values
-
NEWENV
protected static final int NEWENV
Telnet Option: Environment- See Also:
- Constant Field Values
-
NE_INFO
protected static final int NE_INFO
- See Also:
- Constant Field Values
-
NE_VAR
protected static final int NE_VAR
The following are constants for supported options, which can be negotiated based upon the telnet protocol specification.- See Also:
- Constant Field Values
-
NE_VALUE
protected static final int NE_VALUE
- See Also:
- Constant Field Values
-
NE_ESC
protected static final int NE_ESC
The following options are options for which we also support subnegotiation based upon the telnet protocol specification.- See Also:
- Constant Field Values
-
NE_USERVAR
protected static final int NE_USERVAR
- See Also:
- Constant Field Values
-
NE_VAR_OK
protected static final int NE_VAR_OK
- See Also:
- Constant Field Values
-
NE_VAR_DEFINED
protected static final int NE_VAR_DEFINED
- See Also:
- Constant Field Values
-
NE_VAR_DEFINED_EMPTY
protected static final int NE_VAR_DEFINED_EMPTY
- See Also:
- Constant Field Values
-
NE_VAR_UNDEFINED
protected static final int NE_VAR_UNDEFINED
- See Also:
- Constant Field Values
-
NE_IN_ERROR
protected static final int NE_IN_ERROR
- See Also:
- Constant Field Values
-
NE_IN_END
protected static final int NE_IN_END
- See Also:
- Constant Field Values
-
NE_VAR_NAME_MAXLENGTH
protected static final int NE_VAR_NAME_MAXLENGTH
- See Also:
- Constant Field Values
-
NE_VAR_VALUE_MAXLENGTH
protected static final int NE_VAR_VALUE_MAXLENGTH
- See Also:
- Constant Field Values
-
EXT_ASCII
protected static final int EXT_ASCII
Unused- See Also:
- Constant Field Values
-
SEND_LOC
protected static final int SEND_LOC
- See Also:
- Constant Field Values
-
AUTHENTICATION
protected static final int AUTHENTICATION
- See Also:
- Constant Field Values
-
ENCRYPT
protected static final int ENCRYPT
- See Also:
- Constant Field Values
-
-
Method Detail
-
initIO
public void initIO() throws IOException- Throws:
IOException
-
setConnection
public void setConnection(Connection con)
-
write
public void write(byte b) throws IOExceptionMethod to output a byte. Ensures that CR(\r) is never send alone,but CRLF(\r\n), which is a rule of the telnet protocol.- Parameters:
b- Byte to be written.- Throws:
IOException- if an error occurs
-
write
public void write(int i) throws IOExceptionMethod to output an int.- Parameters:
i- Integer to be written.- Throws:
IOException- if an error occurs
-
write
public void write(byte[] sequence) throws IOExceptionMethod to write an array of bytes.- Parameters:
sequence- byte[] to be written.- Throws:
IOException- if an error occurs
-
write
public void write(int[] sequence) throws IOExceptionMethod to output an array of int' s.- Parameters:
sequence- int [] to write- Throws:
IOException- if an error occurs
-
write
public void write(char ch) throws IOExceptionMethod to write a char.- Parameters:
ch- char to be written.- Throws:
IOException- if an error occurs
-
write
public void write(String str) throws IOException
Method to output a string.- Parameters:
str- String to be written.- Throws:
IOException- if an error occurs
-
flush
public void flush() throws IOExceptionMethod to flush all buffered output.- Throws:
IOException- if an error occurs
-
closeOutput
public void closeOutput()
Method to close the underlying output stream to free system resources.
Most likely only to be called by the ConnectionManager upon clean up of connections that ended or died.
-
read
public int read() throws IOExceptionMethod to read a byte from the InputStream. Invokes the IACHandler upon IAC (Byte=255).- Returns:
- int read from stream.
- Throws:
IOException- if an error occurs
-
closeInput
public void closeInput()
Method to close the underlying inputstream to free system resources.
Most likely only to be called by the ConnectionManager upon clean up of connections that ended or died.
-
setEcho
public void setEcho(boolean b)
-
-