Class TelnetConnection

java.lang.Object
org.aesh.terminal.telnet.TelnetConnection
Direct Known Subclasses:
NettyTelnetConnection

public abstract class TelnetConnection extends Object
Abstract base class for managing Telnet protocol connections and option negotiation.
Author:
Julien Viet
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
    Telnet DO option negotiation byte.
    static final byte
    Telnet DON'T option negotiation byte.
    static final byte
    Telnet IAC (Interpret As Command) byte.
    static final byte
    Telnet SB (subnegotiation begin) byte.
    static final byte
    Telnet SE (subnegotiation end) byte.
    static final byte
    Telnet WILL option negotiation byte.
    static final byte
    Telnet WON'T option negotiation byte.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new TelnetConnection with the specified handler.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Closes the telnet connection.
    protected abstract void
     
    protected void
     
    void
    Initializes the connection and notifies the handler that it is open.
    protected void
    onOptionDo(byte optionCode)
    Handle option DO call back.
    protected void
    onOptionDont(byte optionCode)
    Handle option DON'T call back.
    protected void
    onOptionParameters(byte optionCode, byte[] parameters)
    Handle option parameters call back.
    protected void
    onOptionWill(byte optionCode)
    Handle option WILL call back.
    protected void
    onOptionWont(byte optionCode)
    Handle option WON'T call back.
    void
    receive(byte[] data)
    Receives and processes incoming data from the telnet client.
    protected abstract void
    schedule(Runnable task, long delay, TimeUnit unit)
     
    protected abstract void
    send(byte[] data)
     
    final void
    write(byte[] data)
    Write data to the client, escaping data if necessary or truncating it.
    final void
    Write a do option request to the client.
    final void
    Write a do will request to the client.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BYTE_IAC

      public static final byte BYTE_IAC
      Telnet IAC (Interpret As Command) byte.
      See Also:
    • BYTE_DONT

      public static final byte BYTE_DONT
      Telnet DON'T option negotiation byte.
      See Also:
    • BYTE_DO

      public static final byte BYTE_DO
      Telnet DO option negotiation byte.
      See Also:
    • BYTE_WONT

      public static final byte BYTE_WONT
      Telnet WON'T option negotiation byte.
      See Also:
    • BYTE_WILL

      public static final byte BYTE_WILL
      Telnet WILL option negotiation byte.
      See Also:
    • BYTE_SB

      public static final byte BYTE_SB
      Telnet SB (subnegotiation begin) byte.
      See Also:
    • BYTE_SE

      public static final byte BYTE_SE
      Telnet SE (subnegotiation end) byte.
      See Also:
  • Constructor Details

    • TelnetConnection

      public TelnetConnection(TelnetHandler handler)
      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

      public final void writeDoOption(Option option)
      Write a do option request to the client.
      Parameters:
      option - the option to send
    • writeWillOption

      public final void writeWillOption(Option option)
      Write a do will request to the client.
      Parameters:
      option - the option to send
    • execute

      protected abstract void execute(Runnable task)
    • schedule

      protected abstract void schedule(Runnable task, long delay, TimeUnit unit)
    • send

      protected abstract void send(byte[] data)
    • 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
    • onClose

      protected void onClose()
    • onOptionWill

      protected void onOptionWill(byte optionCode)
      Handle option WILL call back. The implementation will try to find a matching option via the Option#values() and invoke it's Option.handleWill(TelnetConnection) method otherwise a DON'T will 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 option WON'T call back. The implementation will try to find a matching option via the Option#values() and invoke it's Option.handleWont(TelnetConnection) method.

      This method can be subclassed to handle an option.

      Parameters:
      optionCode - the option code
    • onOptionDo

      protected void onOptionDo(byte optionCode)
      Handle option DO call back. The implementation will try to find a matching option via the Option#values() and invoke it's Option.handleDo(TelnetConnection) method otherwise a WON'T will 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 option DON'T call back. The implementation will try to find a matching option via the Option#values() and invoke it's Option.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 the Option#values() and invoke it's Option.handleParameters(TelnetConnection, byte[]) method. This method can be subclassed to handle an option.
      Parameters:
      optionCode - the option code