3

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

I read about them in the github page for socket.io

https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

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 --------------------

https://groups.google.com/forum/?fromgroups#!topic/socket_io/2hn52Udb-3A

Advantage/disadvantage of using socketio heartbeats

Socket.io "connection" event fired on every client heartbeat?

Is it safe to set a high close timeout on socket.io?

Community
  • 1
  • 1
Nav
  • 10,304
  • 20
  • 56
  • 83

1 Answers1

10

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 socket.io 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.

robertklep
  • 198,204
  • 35
  • 394
  • 381
  • I am using io.set('transports', ['jsonp-polling']); io.set("polling duration", 1); so for this what should be the values of heartbeat and close timeout......currently i have these io.set("close timeout", 2); io.set("heartbeat interval", 2); are these ok ??? or can i make them 1?? – Nav May 29 '13 at 10:39
  • Heartbeats aren't used for the polling transports, so it doesn't matter what you set it to. As for the close timeout, I would leave it set to the default. However, I think your `polling duration` is quite low, it means that the client is giving the JSONP request only 1 second to complete! – robertklep May 29 '13 at 10:47
  • is close time used for the polling transports...i m a little marky..can you please explain this a little in detail as to how close timeout and heartbeat interval are related or not ??? – Nav May 29 '13 at 11:28
  • I edited my answer w.r.t close timeout vs heartbeat interval. As for the use of `close timeout` in polling transports: I think it's still used. – robertklep May 29 '13 at 11:36