Disabling Socket.io heartbeats (Node.js)
Question
The socket.io documentation mentions that heartbeats can be disabled like so:
io.disable('heartbeats');
Unfortunately, while this seems to stop the hearbeats from being sent, the clients still disconnect when they are not sending hearbeats.
The following does not function either:
io.set('heartbeats', false);
I have tried setting some intervals to 0, without success:
io.set('heartbeat timeout', 0);
io.set('heartbeat interval', 0);
Any suggestions on what might properly disable heartbeats?
Solution
The code is
io.disable('heartbeats');
Tested successfully on socket.io v0.8.7
Without disabling
debug - emitting heartbeat for client 299833185260419425
debug - websocket writing 2::
debug - set heartbeat timeout for client 299833185260419425
debug - got heartbeat packet
debug - cleared heartbeat timeout for client 299833185260419425
debug - set heartbeat interval for client 299833185260419425
With disabling
debug - client authorized
info - handshake authorized 1205975980561506547
debug - setting request GET /socket.io/1/websocket/1205975980561506547
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"name":"news","args":[{"hello":"foo"}]}
OTHER TIPS
There is something wrong with heartbeats. I have latest socket.io and node 0.6.X
info - socket.io started
debug - client authorized
info - handshake authorized 734447051478827620
debug - setting request GET /socket.io/1/websocket/734447051478827620
debug - client authorized for
debug - websocket writing 1::
debug - websocket writing 5:::{"name":"hello"}
info - transport end (socket end)
debug - set close timeout for client 734447051478827620
debug - cleared close timeout for client 734447051478827620
debug - discarding transport
// server code
var io = require('socket.io').listen(8080);
io.disable('heartbeats');
io.sockets.on('connection', function (socket) {
socket.emit('hello');
});
Client is disconnected right after connection.
Set the log level of socket.io, with log level 2 we wont see all the heartbeats of each socket but only the handshakes and disconnections
io.set('log level', 2);