Module com.googlecode.lanterna
Class TelnetTerminalServer
- java.lang.Object
-
- com.googlecode.lanterna.terminal.ansi.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. UseacceptConnection()
to wait for the next incoming connection, it will be returned as aTelnetTerminal
object that represents the client and which will be the way for the server to send content to this client. Next connecting client (throughacceptConnection()
will get a differentTelnetTerminal
, 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 portTelnetTerminalServer(int port, java.nio.charset.Charset charset)
Creates a new TelnetTerminalServer on a specific port, using a certain character setTelnetTerminalServer(javax.net.ServerSocketFactory serverSocketFactory, int port)
Creates a new TelnetTerminalServer on a specific port through a ServerSocketFactoryTelnetTerminalServer(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.
-
-
-
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 connectionscharset
- 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 connectionsserverSocketFactory
- 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 ServerSocketport
- Port to listen for incoming telnet connectionscharset
- 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
-
-