-
Notifications
You must be signed in to change notification settings - Fork 10
Handle Socket
Page Content:
- Listen on events from the client
- Send events to the client
- ClusterWS JavaScript Client reserved events
Note: that send
method allows only direct server <-> client
communication, don't use send
method to communicate between different clients as it will not scale, for communication between different clients use Pub/Sub
system.
To listen on events which are send from the server use on
method provided by socket
:
// Listen on method from client
socket.on('myeventname', (data) => {
// your code to execute on event
})
To send message to the server use send
method provided by socket
:
// you can send any 'data'
socket.send('nameoftheevent', data)
Note: do not to send events which starts with #
or reserved events such as disconnect
, connection
, error
.
// 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
})
💥 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