禁用Socket.io检测信号(Node.js)
socket.io文档提到可以像这样禁用心跳:
io.disable('heartbeats');
不幸的是,虽然这似乎阻止了发送的聆听,但是当不发送聆听时,客户仍然断开连接。
以下内容不起作用:
io.set('heartbeats', false);
我试图设置一些间隔为0,没有成功:
io.set('heartbeat timeout', 0); io.set('heartbeat interval', 0);
有什么build议可以正确地禁用心跳?
代码是
io.disable('heartbeats');
在socket.io v0.8.7上testing成功
不禁用
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
禁用
debugging – 客户端授权
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"}]}
心跳有问题。 我有最新的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'); });
客户端连接后立即断开连接。
设置socket.io的日志级别,日志级别2我们不会看到每个套接字的所有心跳,但只有握手和断开连接
io.set('log level',2);