2011-09-08 53 views
4

socket.io documentation提到,心跳可以像这样被禁用:禁用Socket.io心跳(Node.js的)

io.disable('heartbeats');

不幸的是,虽然这似乎被发送停止hearbeats,该客户端仍然断开当他们不发送听力。

下不起作用或者:

io.set('heartbeats', false);

我已经尝试了一些时间间隔设置为0,没有成功:

io.set('heartbeat timeout', 0); 
io.set('heartbeat interval', 0); 

上什么可能正确禁用心跳有什么建议?

+1

您的最终目标是什么? – EhevuTov

+0

两个矛盾的答案:/ – UpTheCreek

+0

请注意,我的问题是从9月8日'11,失效机制可能已经被修复了。 – Tom

回答

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 

随着禁用

调试 - 客户端授权

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"}]} 
+0

只是偶然发现了这一点。汤姆是否确定它在工作?我不认为这与他所说的他试图无效的工作有什么不同。 – NateDSaint

+0

这对我来说是最新的0.9.X引起的错误,但是在将socket.io切换到0.8.7后,您提到它可以工作......我假设它是某处的错误。 – idolize

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

客户端连接后立即断开连接。

0

设置socket.io的日志级别,与日志级别2,我们不会看到每个插槽的所有心跳,但只有握手和断开

io.set(“日志级别”,2);