The Socket.IO socket

The socket.io socket emulates a network socket over different transport mechanisms. Just as any other socket, it has various stages in its lifecycle, depending on the status of the connection. These are as follows:

  • connecting
  • connected
  • disconnecting
  • disconnected

The socket is established when the client sends a connection request to the server and a handshake is initiated.

Once the handshake is complete, a connection is opened using the transport negotiated during the handshake, and the state of the socket is set to connected.

To check the liveliness of the socket depending on the server configuration, the server may require heartbeat messages to be sent from the client to the server in regular intervals. In the absence of such a message, or the failure of the underlying transport, the socket will be disconnected.

In this case, the client will initiate a reconnect. If the connection is restored within the connection termination time or the timeout agreed at the time of the handshake, the buffered messages are sent across. In case the connection is not restored, the client will start a new connection request, beginning with a new handshake.

Also, optionally, to ensure message delivery over the socket, we can make it compulsory for the socket to acknowledge the message delivery.

The socket is terminated when the close method is called on either the client or the server.

..................Content has been hidden....................

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