public final class Client extends NetworkConnection
Example:
// server ip
Client client = new Client("127.0.0.1");
// add relevant parsers for messages from server
client.addParser(String.class, data -> System.out.println(data));
// connect to server
client.connect();
// send some messages
client.send("This is an example message");
// when done, disconnect from server
client.disconnect();
connectionActivePropertyparsers| Constructor and Description |
|---|
Client(String serverIP)
Constructs a new client with given server IP configuration.
|
Client(String serverIP,
int tcpPort,
int udpPort)
Constructs a new client with given server IP and
tcp/udp ports configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
boolean |
connect()
Performs an actual (blocking for 10 sec) connection to the server.
|
void |
disconnect()
Sends a message to server that client is
about to disconnect and shuts down connection threads.
|
protected void |
sendTCP(Serializable data) |
protected void |
sendUDP(Serializable data) |
addParser, connectionActiveProperty, getParsers, handleError, isConnectionActive, onConnectionClosed, onConnectionOpen, send, send, sendClosingMessage, setExceptionHandler, setOnConnectionClosed, setOnConnectionOpen, setParsers, toByteArraypublic Client(String serverIP)
serverIP - ip of the server machinepublic Client(String serverIP, int tcpPort, int udpPort)
serverIP - ip of the server machinetcpPort - tcp port to useudpPort - udp port to usepublic boolean connect()
throws Exception
Exceptionpublic void disconnect()
Further calls to NetworkConnection.send(Serializable) will
throw IllegalStateException
public void close()
close in class NetworkConnectionprotected void sendUDP(Serializable data)
sendUDP in class NetworkConnectionprotected void sendTCP(Serializable data)
sendTCP in class NetworkConnectionCopyright © 2018. All rights reserved.