user8408221
user8408221

Reputation:

Socket get disconnected randomly

Client Socket randomly disconnects because of a ping timeout

At the server side, I am listening the disconnected event.

Output:

Socket disconnected because of ping timeout

socket.on('disconnect', function (reason) {
    console.log('Socket disconnected because of ' + reason);
});

Upvotes: 3

Views: 4123

Answers (1)

Jeba
Jeba

Reputation: 868

Due to the inactivity it throws that error.

If server not able to communicate the Client particular interval of time which is ping interval time.

Ref: https://socket.io/docs/server-api/

pingTimeout (Number): how many ms without a pong packet to consider the connection closed (60000) pingInterval (Number): how many ms before sending a new ping packet (25000).

Those two parameters will impact the delay before a client knows the server is not available anymore. For example, if the underlying TCP connection is not closed properly due to a network issue, a client may have to wait up to pingTimeout + pingInterval ms before getting a disconnect event.

Upvotes: 2

Related Questions