Client events

In this section we will get to know some client-side events.

connect

The connect event is emitted when the socket is connected successfully:

socket.on('connect', function () {})

connecting

The connecting event is emitted when the socket is attempting to connect with the server:

socket.on('connecting', function () {})

disconnect

The disconnect event is emitted when the socket is disconnected:

socket.on('disconnect', function () {})

connect_failed

The connect_failed event is emitted when socket.io fails to establish a connection to the server for reasons such as when none of the transports work or authorization failed:

socket.on('connect_failed', function () {})

error

The error event is emitted when an error occurs and it cannot be handled by the other event types:

socket.on('error', function () {})

message

The message event is emitted when a message sent with socket.send is received:

socket.on('message', function (<message>, <ack_callback>) {})

Here, message is the sent message and ack_callback is an optional acknowledgment function.

reconnect

The reconnect event is emitted when socket.io successfully reconnects to the server:

socket.on('reconnect', function () {})

reconnecting

The reconnecting event is emitted when the socket is attempting to reconnect with the server:

socket.on('reconnecting', function () {})

reconnect_failed

The reconnect_failed event is emitted when socket.io fails to reestablish a working connection after the connection was dropped:

socket.on('reconnect_failed', function () {})
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset