Package org.jline.builtins.telnet
Class TelnetIO
java.lang.Object
org.jline.builtins.telnet.TelnetIO
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
Modifier and TypeFieldDescriptionprotected static final int
Abort Outputprotected static final int
protected static final int
Are You Thereprotected static final int
Breakprotected static final int
Data mark its the data part of a SYNCH which helps to clean up the buffers between Telnet Server <-> Telnet Client.protected static final int
Negotiation: Do optionprotected static final int
Negotiation: Dont do optionprotected static final int
Erase Charprotected static final int
Telnet Option: ECHOprotected static final int
Erase Lineprotected static final int
protected static final int
Unusedprotected static final int
Go Ahead
Newer Telnets do not make use of this option that allows a specific communication mode.protected static final int
Interpret As Commandprotected static final int
Interrupt Processprotected static final int
TTYPE subnegotiation: ISprotected static final int
Telnet Option: Linemodeprotected static final int
protected static final int
protected static final int
protected static final int
Following methods implement init/request/answer procedures for telnet protocol level communication.protected static final int
protected static final int
The following implement the NVT (network virtual terminal) which offers the concept of a simple "printer".protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
Constants declarationprotected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
End telnet protocol level communication methodsprotected static final int
protected static final int
Telnet Option: Logout
This allows nice goodbye to time-outed or unwanted clients.protected static final int
Telnet Option: Negotiate About Window Size
Server request is IAC DO NAWS Client response contains subnegotiation with data (columns, rows).protected static final int
The following options are options for which we also support subnegotiation based upon the telnet protocol specification.protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
The following are constants for supported options, which can be negotiated based upon the telnet protocol specification.protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
protected static final int
Telnet Option: Environmentprotected static final int
No operationprotected static final int
Marks start of a subnegotiation.protected static final int
Marks end of subnegotiation.protected static final int
TTYPE subnegotiation: SENDprotected static final int
protected static final int
Telnet Option: SUPress Go Ahead
This will be negotiated, all new telnet protocol implementations are recommended to do this.protected static final int
Telnet Option: Terminal TYPE
Server request contains subnegotiation SEND Client response contains subnegotiation with data IS,terminal type stringprotected static final int
Negotiation: Will do optionprotected static final int
Negotiation: Wont do option -
Constructor Summary
ConstructorDescriptionTelnetIO()
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
Modifier and TypeMethodDescriptionvoid
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.void
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.void
flush()
Method to flush all buffered output.void
initIO()
int
read()
Method to read a byte from the InputStream.void
setConnection
(Connection con) void
setEcho
(boolean b) void
write
(byte b) Method to output a byte.void
write
(byte[] sequence) Method to write an array of bytes.void
write
(char ch) Method to write a char.void
write
(int i) Method to output an int.void
write
(int[] sequence) Method to output an array of int' s.void
Method to output a string.
-
Field Details
-
IAC
protected static final int IACInterpret As Command- See Also:
-
GA
protected static final int GAGo Ahead
Newer Telnets do not make use of this option that allows a specific communication mode.- See Also:
-
WILL
protected static final int WILLNegotiation: Will do option- See Also:
-
WONT
protected static final int WONTNegotiation: Wont do option- See Also:
-
DO
protected static final int DONegotiation: Do option- See Also:
-
DONT
protected static final int DONTNegotiation: Dont do option- See Also:
-
SB
protected static final int SBMarks start of a subnegotiation.- See Also:
-
SE
protected static final int SEMarks end of subnegotiation.- See Also:
-
NOP
protected static final int NOPNo operation- See Also:
-
DM
protected static final int DMData 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:
-
BRK
protected static final int BRKBreak- See Also:
-
IP
protected static final int IPInterrupt Process- See Also:
-
AO
protected static final int AOAbort Output- See Also:
-
AYT
protected static final int AYTAre You There- See Also:
-
EC
protected static final int ECErase Char- See Also:
-
EL
protected static final int ELErase Line- See Also:
-
ECHO
protected static final int ECHOTelnet Option: ECHO- See Also:
-
SUPGA
protected static final int SUPGATelnet Option: SUPress Go Ahead
This will be negotiated, all new telnet protocol implementations are recommended to do this.- See Also:
-
NAWS
protected static final int NAWSTelnet Option: Negotiate About Window Size
- Server request is IAC DO NAWS
- Client response contains subnegotiation with data (columns, rows).
- See Also:
-
TTYPE
protected static final int TTYPETelnet Option: Terminal TYPE
- Server request contains subnegotiation SEND
- Client response contains subnegotiation with data IS,terminal type string
- See Also:
-
IS
protected static final int ISTTYPE subnegotiation: IS- See Also:
-
SEND
protected static final int SENDTTYPE subnegotiation: SEND- See Also:
-
LOGOUT
protected static final int LOGOUTTelnet Option: Logout
This allows nice goodbye to time-outed or unwanted clients.- See Also:
-
LINEMODE
protected static final int LINEMODETelnet Option: LinemodeThe infamous line mode option.
- See Also:
-
LM_MODE
protected static final int LM_MODE- See Also:
-
LM_EDIT
protected static final int LM_EDIT- See Also:
-
LM_TRAPSIG
protected static final int LM_TRAPSIG- See Also:
-
LM_MODEACK
protected static final int LM_MODEACKFollowing methods implement init/request/answer procedures for telnet protocol level communication.- See Also:
-
LM_FORWARDMASK
protected static final int LM_FORWARDMASK- See Also:
-
LM_SLC
protected static final int LM_SLC- See Also:
-
LM_SLC_NOSUPPORT
protected static final int LM_SLC_NOSUPPORT- See Also:
-
LM_SLC_DEFAULT
protected static final int LM_SLC_DEFAULT- See Also:
-
LM_SLC_VALUE
protected static final int LM_SLC_VALUEEnd telnet protocol level communication methods- See Also:
-
LM_SLC_CANTCHANGE
protected static final int LM_SLC_CANTCHANGEConstants declaration- See Also:
-
LM_SLC_LEVELBITS
protected static final int LM_SLC_LEVELBITS- See Also:
-
LM_SLC_ACK
protected static final int LM_SLC_ACK- See Also:
-
LM_SLC_FLUSHIN
protected static final int LM_SLC_FLUSHIN- See Also:
-
LM_SLC_FLUSHOUT
protected static final int LM_SLC_FLUSHOUT- See Also:
-
LM_SLC_SYNCH
protected static final int LM_SLC_SYNCH- See Also:
-
LM_SLC_BRK
protected static final int LM_SLC_BRK- See Also:
-
LM_SLC_IP
protected static final int LM_SLC_IP- See Also:
-
LM_SLC_AO
protected static final int LM_SLC_AO- See Also:
-
LM_SLC_AYT
protected static final int LM_SLC_AYT- See Also:
-
LM_SLC_EOR
protected static final int LM_SLC_EOR- See Also:
-
LM_SLC_ABORT
protected static final int LM_SLC_ABORTThe 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:
-
LM_SLC_EOF
protected static final int LM_SLC_EOF- See Also:
-
LM_SLC_SUSP
protected static final int LM_SLC_SUSP- See Also:
-
NEWENV
protected static final int NEWENVTelnet Option: Environment- See Also:
-
NE_INFO
protected static final int NE_INFO- See Also:
-
NE_VAR
protected static final int NE_VARThe following are constants for supported options, which can be negotiated based upon the telnet protocol specification.- See Also:
-
NE_VALUE
protected static final int NE_VALUE- See Also:
-
NE_ESC
protected static final int NE_ESCThe following options are options for which we also support subnegotiation based upon the telnet protocol specification.- See Also:
-
NE_USERVAR
protected static final int NE_USERVAR- See Also:
-
NE_VAR_OK
protected static final int NE_VAR_OK- See Also:
-
NE_VAR_DEFINED
protected static final int NE_VAR_DEFINED- See Also:
-
NE_VAR_DEFINED_EMPTY
protected static final int NE_VAR_DEFINED_EMPTY- See Also:
-
NE_VAR_UNDEFINED
protected static final int NE_VAR_UNDEFINED- See Also:
-
NE_IN_ERROR
protected static final int NE_IN_ERROR- See Also:
-
NE_IN_END
protected static final int NE_IN_END- See Also:
-
NE_VAR_NAME_MAXLENGTH
protected static final int NE_VAR_NAME_MAXLENGTH- See Also:
-
NE_VAR_VALUE_MAXLENGTH
protected static final int NE_VAR_VALUE_MAXLENGTH- See Also:
-
EXT_ASCII
protected static final int EXT_ASCIIUnused- See Also:
-
SEND_LOC
protected static final int SEND_LOC- See Also:
-
AUTHENTICATION
protected static final int AUTHENTICATION- See Also:
-
ENCRYPT
protected static final int ENCRYPT- See Also:
-
-
Constructor Details
-
TelnetIO
public 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 Details
-
initIO
- Throws:
IOException
-
setConnection
-
write
Method 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
Method to output an int.- Parameters:
i
- Integer to be written.- Throws:
IOException
- if an error occurs
-
write
Method to write an array of bytes.- Parameters:
sequence
- byte[] to be written.- Throws:
IOException
- if an error occurs
-
write
Method to output an array of int' s.- Parameters:
sequence
- int [] to write- Throws:
IOException
- if an error occurs
-
write
Method to write a char.- Parameters:
ch
- char to be written.- Throws:
IOException
- if an error occurs
-
write
Method to output a string.- Parameters:
str
- String to be written.- Throws:
IOException
- if an error occurs
-
flush
Method 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
Method 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)
-