4

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?

Tom
  • 8,536
  • 31
  • 133
  • 232
  • Note that my question is from Sep 8 '11, the disable mechanic may have been fixed by now. – Tom Jul 13 '12 at 07:02

3 Answers3

4

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"}]}
First Zero
  • 21,586
  • 6
  • 46
  • 45
  • just stumbled upon this. Was Tom just not sure it was working? I don't see how this is different from what he said he was trying to make work with no effect. – NateDSaint Apr 04 '12 at 18:27
  • This was causing errors with the latest 0.9.X for me, but after switching socket.io to 0.8.7 as you mentioned it works... I'm assuming it is a bug somewhere. – idolize Mar 21 '13 at 05:33
3

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.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
Tereska
  • 751
  • 1
  • 7
  • 25
1

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

Vardan
  • 454
  • 1
  • 5
  • 18