Class TelnetTerminalServer

java.lang.Object
com.googlecode.lanterna.terminal.ansi.TelnetTerminalServer

public class TelnetTerminalServer extends Object
This class implements a Telnet server, capable of accepting multiple clients and presenting each one as their own Terminal. You need to tell it at least what port to listen on and then it create a Server socket listening for incoming connections. Use acceptConnection() to wait for the next incoming connection, it will be returned as a TelnetTerminal object that represents the client and which will be the way for the server to send content to this client. Next connecting client (through acceptConnection() will get a different TelnetTerminal, i.e. their content will not be in sync automatically but considered as two different terminals.
See Also:
  • Field Details

    • charset

      private final Charset charset
    • serverSocket

      private final ServerSocket serverSocket
  • Constructor Details

    • TelnetTerminalServer

      public TelnetTerminalServer(int port) throws IOException
      Creates a new TelnetTerminalServer on a specific port
      Parameters:
      port - Port to listen for incoming telnet connections
      Throws:
      IOException - If there was an underlying I/O exception
    • TelnetTerminalServer

      public TelnetTerminalServer(int port, Charset charset) throws IOException
      Creates a new TelnetTerminalServer on a specific port, using a certain character set
      Parameters:
      port - Port to listen for incoming telnet connections
      charset - Character set to use
      Throws:
      IOException - If there was an underlying I/O exception
    • TelnetTerminalServer

      public TelnetTerminalServer(ServerSocketFactory serverSocketFactory, int port) throws IOException
      Creates a new TelnetTerminalServer on a specific port through a ServerSocketFactory
      Parameters:
      serverSocketFactory - ServerSocketFactory to use when creating the ServerSocket
      port - Port to listen for incoming telnet connections
      Throws:
      IOException - If there was an underlying I/O exception
    • TelnetTerminalServer

      public TelnetTerminalServer(ServerSocketFactory serverSocketFactory, int port, Charset charset) throws IOException
      Creates a new TelnetTerminalServer on a specific port through a ServerSocketFactory with a certain Charset
      Parameters:
      serverSocketFactory - ServerSocketFactory to use when creating the ServerSocket
      port - Port to listen for incoming telnet connections
      charset - Character set to use
      Throws:
      IOException - If there was an underlying I/O exception
  • Method Details

    • getServerSocket

      public ServerSocket getServerSocket()
      Returns the actual server socket used by this object. Can be used to tweak settings but be careful!
      Returns:
      Underlying ServerSocket
    • acceptConnection

      public TelnetTerminal acceptConnection() throws IOException
      Waits for the next client to connect in to our server and returns a Terminal implementation, TelnetTerminal, that represents the remote terminal this client is running. The terminal can be used just like any other Terminal, but keep in mind that all operations are sent over the network.
      Returns:
      TelnetTerminal for the remote client's terminal
      Throws:
      IOException - If there was an underlying I/O exception
    • close

      public void close() throws IOException
      Closes the server socket, accepting no new connection. Any call to acceptConnection() after this will fail.
      Throws:
      IOException - If there was an underlying I/O exception