I have mobile clients connected to a node.js server, running socket.io via xhr-polling. I have two type of clients:
-
Type A
When the connection breaks up due to network problems (or that the
client crashes) the default heart beat timeout is too long -
Type B
When the connection breaks up for this client I need to give it more
time to recover – it is more important that the client recovers than
the server breaks the connection/session
So my question is how to I configure (if it is possible) the heartbeat timeouts from the actual client?
As far as I can tell, there are 2 values that matter here: the server sends heartbeats to the client every
heartbeat intervalseconds; the client responds directly, if there is no response, the server decides the client is dead. The client waits for a heartbeat from the server forheartbeat timeoutseconds since the last heartbeat (which should obviously be higher than theheartbeat interval). If it hasn’t received word from the server inheartbeat timeoutseconds, it assumes the server is dead (and will start disconnecting / reconnecting based on the other options you have set.Default values are
heartbeat interval = 25sandheartbeat timeout = 60s. Both items are set on the server, theheartbeat timeoutis sent to the client upon connecting.Changing the
heartbeat timeoutfor a single client is easy:However on the server, the
heartbeat intervalvalue seems to be part of a shared object (the Manager, which is what you get back from yourvar io = require("socket.io").listen(server)call), which means that it can’t easily be changed for individual sockets.I’m sure that with some socket.io hacking you should be able to make it happen, but you might break other stuff in the process…