Javascript – what is the difference between close timeout and heartbeat interval in

Well as the question says what's the difference between close timeout and heartbeat interval parameters in

I read about them in the github page for

But,couldn't quite understand the difference as to how are they related and if the values for both should be same or not in the case when I am manually configuring them.

Some more materials regarding this topic I came about ——————–!topic/socket_io/2hn52Udb-3A

Advantage/disadvantage of using socketio heartbeats "connection" event fired on every client heartbeat?

Is it safe to set a high close timeout on

Best Solution

The documentation indeed isn't very clear.

As far as I understand it (also looking at the code):

  • close timeout sets a sort of 'grace period' when either the client or the server closes the connection: instead of closing it immediately, it will first wait close timeout seconds; if, within that period of time, the client decides to reconnect, send data, or receives data from the server, the connection will be reused (and the timeout will be cleared). Otherwise, when nothing has happened after the timeout, the connection is really closed;
  • heartbeat timeout: if, after this many seconds, the client hasn't responded to a heartbeat message from the server, the server will consider the connection to be lost (or the client to be non-responsive) and will close it;
  • heartbeat interval: this sets the interval between heartbeat messages (used by the server to check if the client is still connected); by default, it sends a message every 25 seconds;

close timeout and heartbeat timeout aren't really related, I don't think they have to have the same value.

EDIT: as for close timeout and heartbeat interval, I'm not sure. It could be that the heartbeat-message will cancel the close timeout, but it that were true, the default values that sets (25 and 60 seconds, respectively) don't make much sense.

EDIT #2: heartbeat-messages don't seem to cancel the close timeout, so they are unrelated.