Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Handle Socket

Dmitrii Goriunov edited this page Jan 4, 2018 · 8 revisions

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)

Listen on events from server

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
})
...

Send events to the server

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.

English:

1. Home

2. Installation and Configuration

3. Handle Socket

4. Pub/Sub System

5. Client to Client Communication

Other languages will be added later

Clone this wiki locally