-
Notifications
You must be signed in to change notification settings - Fork 3
Handle Socket
ClusterWS Java Client provides an easy interface to communicate with ClusterWS server.
Please note that send
and on
events are used only for server
<-> client
communication, you won't be able to communicate with another user across different CPU and Machines. To communicate with another user across CPU and Machines use Pub/Sub system. (check client
<-> client
communication guide for more information)
To listen on events which are send from server you should use on
method:
socket.on("my-event-name", new IEmitterListener() {
@Override
public void onDataReceived(Object data) {
// your code to execute on event
}
});
ClusterWS Java Client reserved events:
socket.setClusterWSListener(new IClusterWSListener() {
@Override
public void onConnected() {
// executed when client is connected to the server
// your code to execute on event
}
@Override
public void onError(Exception exception) {
// executed when some error has happened
// your code to execute on event
}
@Override
public void onDisconnected(int code, String reason) {
// executed when client is disconnected from the server
// your code to execute on event
}
});
To send message to the server you should use send
method:
socket.send("my-event-name", "any-data-you-want");
Try to do not send events which starts with #
or reserved disconnect
, connection
, error
events.
💥 We would really appreciate if you give us stars ⭐ (on all our repositories):
For you to give the stars ⭐ is not hard, but for us, it is a huge motivation to work harder and improve the project. Thank you very much 😄.