Class TelnetConnection
java.lang.Object
org.aesh.terminal.telnet.TelnetConnection
- Direct Known Subclasses:
NettyTelnetConnection
Abstract base class for managing Telnet protocol connections and option negotiation.
- Author:
- Julien Viet
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteTelnet DO option negotiation byte.static final byteTelnet DON'T option negotiation byte.static final byteTelnet IAC (Interpret As Command) byte.static final byteTelnet SB (subnegotiation begin) byte.static final byteTelnet SE (subnegotiation end) byte.static final byteTelnet WILL option negotiation byte.static final byteTelnet WON'T option negotiation byte. -
Constructor Summary
ConstructorsConstructorDescriptionTelnetConnection(TelnetHandler handler) Creates a new TelnetConnection with the specified handler. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Closes the telnet connection.protected abstract voidExecute a task.protected voidonClose()Method.voidonInit()Initializes the connection and notifies the handler that it is open.protected voidonOptionDo(byte optionCode) Handle optionDOcall back.protected voidonOptionDont(byte optionCode) Handle optionDON'Tcall back.protected voidonOptionParameters(byte optionCode, byte[] parameters) Handle option parameters call back.protected voidonOptionWill(byte optionCode) Handle optionWILLcall back.protected voidonOptionWont(byte optionCode) Handle optionWON'Tcall back.protected voidPauses reading from the underlying transport.voidreceive(byte[] data) Receives and processes incoming data from the telnet client.protected voidResumes reading from the underlying transport after a previouspauseReads()call.protected abstract voidSchedule a task.protected abstract voidsend(byte[] data) Send data.final voidwrite(byte[] data) Write data to the client, escaping data if necessary or truncating it.final voidwrite(byte[] data, int off, int len) Write data from a buffer slice.final voidwriteDoOption(Option option) Write a do option request to the client.final voidwriteWillOption(Option option) Write a do will request to the client.
-
Field Details
-
BYTE_IAC
public static final byte BYTE_IACTelnet IAC (Interpret As Command) byte.- See Also:
-
BYTE_DONT
public static final byte BYTE_DONTTelnet DON'T option negotiation byte.- See Also:
-
BYTE_DO
public static final byte BYTE_DOTelnet DO option negotiation byte.- See Also:
-
BYTE_WONT
public static final byte BYTE_WONTTelnet WON'T option negotiation byte.- See Also:
-
BYTE_WILL
public static final byte BYTE_WILLTelnet WILL option negotiation byte.- See Also:
-
BYTE_SB
public static final byte BYTE_SBTelnet SB (subnegotiation begin) byte.- See Also:
-
BYTE_SE
public static final byte BYTE_SETelnet SE (subnegotiation end) byte.- See Also:
-
-
Constructor Details
-
TelnetConnection
Creates a new TelnetConnection with the specified handler.- Parameters:
handler- the handler for processing telnet events
-
-
Method Details
-
onInit
public void onInit()Initializes the connection and notifies the handler that it is open. -
close
public abstract void close()Closes the telnet connection. -
writeDoOption
Write a do option request to the client.- Parameters:
option- the option to send
-
writeWillOption
Write a do will request to the client.- Parameters:
option- the option to send
-
execute
Execute a task.- Parameters:
task- the task to execute
-
pauseReads
protected void pauseReads()Pauses reading from the underlying transport. Used for backpressure when the processing queue is full.Default implementation is a no-op. Subclasses with transport-level read control should override this.
-
resumeReads
protected void resumeReads()Resumes reading from the underlying transport after a previouspauseReads()call. -
schedule
-
send
protected abstract void send(byte[] data) Send data.- Parameters:
data- the data to send
-
receive
public void receive(byte[] data) Receives and processes incoming data from the telnet client.- Parameters:
data- the raw byte data received
-
write
public final void write(byte[] data) Write data to the client, escaping data if necessary or truncating it. The original buffer can be mutated if incorrect data is provided.- Parameters:
data- the data to write
-
write
public final void write(byte[] data, int off, int len) Write data from a buffer slice. Copies the slice into a new array before delegating towrite(byte[])because that method may mutate the array (strips high bit in non-binary mode).- Parameters:
data- the source buffer (not modified)off- the start offset in the bufferlen- the number of bytes to write
-
onClose
protected void onClose()Method. -
onOptionWill
protected void onOptionWill(byte optionCode) Handle optionWILLcall back. The implementation will try to find a matching option via theOption#values()and invoke it'sOption.handleWill(TelnetConnection)method otherwise aDON'Twill be sent to the client.This method can be subclassed to handle an option.
- Parameters:
optionCode- the option code
-
onOptionWont
protected void onOptionWont(byte optionCode) Handle optionWON'Tcall back. The implementation will try to find a matching option via theOption#values()and invoke it'sOption.handleWont(TelnetConnection)method.This method can be subclassed to handle an option.
- Parameters:
optionCode- the option code
-
onOptionDo
protected void onOptionDo(byte optionCode) Handle optionDOcall back. The implementation will try to find a matching option via theOption#values()and invoke it'sOption.handleDo(TelnetConnection)method otherwise aWON'Twill be sent to the client.This method can be subclassed to handle an option.
- Parameters:
optionCode- the option code
-
onOptionDont
protected void onOptionDont(byte optionCode) Handle optionDON'Tcall back. The implementation will try to find a matching option via theOption#values()and invoke it'sOption.handleDont(TelnetConnection)method.This method can be subclassed to handle an option.
- Parameters:
optionCode- the option code
-
onOptionParameters
protected void onOptionParameters(byte optionCode, byte[] parameters) Handle option parameters call back. The implementation will try to find a matching option via theOption#values()and invoke it'sOption.handleParameters(TelnetConnection, byte[])method.This method can be subclassed to handle an option.
- Parameters:
optionCode- the option codeparameters- the option parameters
-