public final class Server extends NetworkConnection
Example:
// create server object with default params, note: no network operation yet
Server server = new Server();
// add relevant parsers for messages from client
server.addParser(String.class, data -> System.out.println(data));
// actual network operation
server.start();
// send some messages
server.send("This is an example message");
// when done, stop the server
server.stop();
connectionActivePropertyparsers| Constructor and Description |
|---|
Server()
Constructs and configures a single-client server with default ports
No network operation is done at this point.
|
Server(int tcpPort,
int udpPort)
Constructs and configures a single-client server with default ports
No network operation is done at this point.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
isConnected() |
protected void |
sendTCP(Serializable data) |
protected void |
sendUDP(Serializable data) |
void |
start()
Starts the server.
|
boolean |
startAndWait(long seconds) |
void |
stop()
Sends a message to all connected clients that
the server is about to shut down.
|
addParser, connectionActiveProperty, getParsers, handleError, isConnectionActive, onConnectionClosed, onConnectionOpen, send, send, sendClosingMessage, setExceptionHandler, setOnConnectionClosed, setOnConnectionOpen, setParsers, toByteArraypublic Server()
public Server(int tcpPort,
int udpPort)
public void start()
public boolean startAndWait(long seconds)
public void stop()
Further calls to NetworkConnection.send(Serializable) will
throw IllegalStateException
public void close()
close in class NetworkConnectionpublic boolean isConnected()
protected void sendUDP(Serializable data)
sendUDP in class NetworkConnectionprotected void sendTCP(Serializable data)
sendTCP in class NetworkConnectionCopyright © 2018. All rights reserved.