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

Handle Socket

Yadushini edited this page Dec 30, 2017 · 8 revisions

ClusterWS JavaScript Client provide an easy interface to communicate with ClusterWS server.

Please note that send and on events are used only to have server <-> client communication, you wont be able to communicate across different CPU and Machines (only if you use publish event from the server). To communicate across CPU and Machines use Pub/Sub system.

Listen on events from server

To listen on events which are sent from server you should use on method:

...
socket.on('my-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 event
})

// executed when some error has happened
socket.on('error', (error) => {
  // your code to execute on event
})

// executed when client is disconnected from the server
socket.on('disconnect', (code, reason) => {
  // your code to execute on event
})
...

Send events to the server

To send message to the server you should use send method:

...
// data can be anything you want
socket.send('my-event-name', data)
...

Try to do not send 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