In this section we will get to know some client-side events.
The connect
event is emitted when the socket is connected successfully:
socket.on('connect', function () {})
The connecting
event is emitted when the socket is attempting to connect with the server:
socket.on('connecting', function () {})
The disconnect
event is emitted when the socket is disconnected:
socket.on('disconnect', function () {})
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 () {})
The error
event is emitted when an error occurs and it cannot be handled by the other event types:
socket.on('error', function () {})
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.
The reconnect
event is emitted when socket.io successfully reconnects to the server:
socket.on('reconnect', function () {})