Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Socket.io heartbeats (Node.js)

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?

like image 958
Tom Avatar asked Feb 23 '23 01:02

Tom


1 Answers

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"}]}
like image 114
First Zero Avatar answered Feb 26 '23 22:02

First Zero