socket.io documentation提到可以禁用心跳:
io.disable('heartbeats');
不幸的是,虽然这似乎阻止了发送的听觉声音,但是当他们没有发送听力时,客户端仍会断开连接。
以下内容不起作用:
io.set('heartbeats', false);
我尝试将一些间隔设置为0,但没有成功:
io.set('heartbeat timeout', 0);
io.set('heartbeat interval', 0);
有关可能正确禁用心跳的建议吗?
答案 0 :(得分:4)
代码是
io.disable('heartbeats');
在socket.io v0.8.7上成功测试
不禁用
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
禁用
debug - 客户授权
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"}]}
答案 1 :(得分:3)
心跳有问题。我有最新的socket.io和节点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');
});
连接后客户端断开连接。
答案 2 :(得分:1)
设置socket.io的日志级别,日志级别为2,我们不会看到每个套接字的所有心跳但只看到握手和断开连接
io.set(' log level',2);