Class TelnetTerminalServer


  • public class TelnetTerminalServer
    extends java.lang.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:
    TelnetTerminal, Wikipedia
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.nio.charset.Charset charset  
      private java.net.ServerSocket serverSocket  
    • Constructor Summary

      Constructors 
      Constructor Description
      TelnetTerminalServer​(int port)
      Creates a new TelnetTerminalServer on a specific port
      TelnetTerminalServer​(int port, java.nio.charset.Charset charset)
      Creates a new TelnetTerminalServer on a specific port, using a certain character set
      TelnetTerminalServer​(javax.net.ServerSocketFactory serverSocketFactory, int port)
      Creates a new TelnetTerminalServer on a specific port through a ServerSocketFactory
      TelnetTerminalServer​(javax.net.ServerSocketFactory serverSocketFactory, int port, java.nio.charset.Charset charset)
      Creates a new TelnetTerminalServer on a specific port through a ServerSocketFactory with a certain Charset
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TelnetTerminal acceptConnection()
      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.
      void close()
      Closes the server socket, accepting no new connection.
      java.net.ServerSocket getServerSocket()
      Returns the actual server socket used by this object.
      • Methods inherited from class java.lang.Object

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

      • charset

        private final java.nio.charset.Charset charset
      • serverSocket

        private final java.net.ServerSocket serverSocket
    • Constructor Detail

      • TelnetTerminalServer

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

        public TelnetTerminalServer​(int port,
                                    java.nio.charset.Charset charset)
                             throws java.io.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:
        java.io.IOException - If there was an underlying I/O exception
      • TelnetTerminalServer

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

        public TelnetTerminalServer​(javax.net.ServerSocketFactory serverSocketFactory,
                                    int port,
                                    java.nio.charset.Charset charset)
                             throws java.io.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:
        java.io.IOException - If there was an underlying I/O exception
    • Method Detail

      • getServerSocket

        public java.net.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 java.io.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:
        java.io.IOException - If there was an underlying I/O exception
      • close

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