java.lang.AutoCloseable, java.lang.Runnablepublic class TcpServer
extends java.lang.Object
implements java.lang.AutoCloseable, java.lang.Runnable
| Modifier and Type | Class | Description |
|---|---|---|
class |
TcpServer.ClientConnection |
| Constructor | Description |
|---|---|
TcpServer(int port) |
|
TcpServer(int port,
int timeout) |
|
TcpServer(int port,
int timeout,
int backLog) |
|
TcpServer(int port,
int timeout,
int backLog,
boolean startImmediately) |
|
TcpServer(int port,
int timeout,
int backLog,
java.net.InetAddress bindAddr) |
|
TcpServer(int port,
int timeout,
int backLog,
java.net.InetAddress bindAddr,
boolean startImmediately) |
| Modifier and Type | Method | Description |
|---|---|---|
void |
addCommandListener(CommandListener listener) |
|
void |
addConnectionListener(ServerConnectionListener listener) |
|
void |
addMessageListener(MessageListener listener) |
|
void |
close() |
Attempts to gracefully-ish shutdown the server and disconnect all existing client connections
|
java.net.InetAddress |
getSocketAddress() |
|
void |
removeAllListeners() |
|
void |
removeCommandListener(CommandListener listener) |
|
void |
removeConnectionListener(ServerConnectionListener listener) |
|
void |
removeMessageListener(MessageListener listener) |
|
void |
run() |
|
void |
sendCommand(java.io.PrintWriter outgoing,
java.security.PublicKey key,
java.lang.String command,
java.lang.String arguments) |
Sends a command to the client
|
void |
sendText(java.io.PrintWriter outgoing,
java.security.PublicKey key,
java.lang.String data) |
Sends a simple message to the client containing
data |
java.util.concurrent.CompletableFuture<java.lang.Void> |
start() |
Starts up the server if it is not already running
|
public TcpServer(int port)
port - port number that the server is to connect topublic TcpServer(int port,
int timeout)
port - port number that the server is to connect totimeout - how many milliseconds of zero activity until a client is automatically disconnectedpublic TcpServer(int port,
int timeout,
int backLog)
port - port number that the server is to connect totimeout - how many milliseconds of zero activity until a client is automatically disconnectedbackLog - how many connections are allowedpublic TcpServer(int port,
int timeout,
int backLog,
java.net.InetAddress bindAddr)
port - port number that the server is to connect totimeout - how many milliseconds of zero activity until a client is automatically disconnectedbackLog - how many connections are allowedbindAddr - the local InetAddress the server will bind to. Leave null if you want to use "localhost"public TcpServer(int port,
int timeout,
int backLog,
boolean startImmediately)
throws ServerException
port - port number that the server is to connect totimeout - how many milliseconds of zero activity until a client is automatically disconnectedbackLog - how many connections are allowedstartImmediately - should the server immediately connect and startServerExceptionpublic TcpServer(int port,
int timeout,
int backLog,
java.net.InetAddress bindAddr,
boolean startImmediately)
throws ServerException
port - port number that the server is to connect totimeout - how many milliseconds of zero activity until a client is automatically disconnectedbackLog - how many connections are allowedstartImmediately - should the server immediately connect and startbindAddr - the local InetAddress the server will bind to. Leave null if you want to use "localhost"ServerExceptionpublic java.net.InetAddress getSocketAddress()
InetAddress of the serverpublic java.util.concurrent.CompletableFuture<java.lang.Void> start()
throws ServerException
CompletableFuture when the server has finished starting upServerException - if something goes wrong during startuppublic void addMessageListener(MessageListener listener)
public void removeMessageListener(MessageListener listener)
public void addCommandListener(CommandListener listener)
public void removeCommandListener(CommandListener listener)
public void addConnectionListener(ServerConnectionListener listener)
public void removeConnectionListener(ServerConnectionListener listener)
public void removeAllListeners()
public void run()
run in interface java.lang.Runnablepublic void sendText(java.io.PrintWriter outgoing,
java.security.PublicKey key,
java.lang.String data)
dataoutgoing - PrintWriter used for sending messages to the clientkey - PublicKey of the client used to encrypt the datadata - String data to be sent to the clientpublic void sendCommand(java.io.PrintWriter outgoing,
java.security.PublicKey key,
java.lang.String command,
java.lang.String arguments)
outgoing - PrintWriter used to communicate to the clientkey - PublicKey of the client used to encrypt the datacommand - the command to be sentarguments - the command argumentspublic void close()
close in interface java.lang.AutoCloseable