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 Dec 28, 2017 · 8 revisions

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

Listen on events from server

To listen on events which are send 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