-
Notifications
You must be signed in to change notification settings - Fork 10
Handle Socket
ClusterWS JavaScript 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 sent from server you should use on
method:
...
socket.on('event-name', (data) => {
// your code to execute on event
})
...
ClusterWS JavaScript Client reserved events:
...
// executed when client is connected to the server
socket.on('connect', () => {
// your code to execute on connect event
})
// executed when error has happened
socket.on('error', (err) => {
// your code to execute on error event
})
// executed when client is disconnected from the server
socket.on('disconnect', (code, reason) => {
// your code to execute on disconnect event
})
...
To send message to the server you should use send
method:
...
socket.send('event-name', 'any-data-you-want')
...
Try to do not use 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 😄.
1. Home
2. Installation and Configuration
5. Client to Client Communication
Other languages will be added later