禁用 Socket.io 心跳 (Node.js)

发布于 2024-12-03 16:39:59 字数 412 浏览 0 评论 0原文

socket.io 文档提到可以像这样禁用心跳:

io.disable('heartbeats');

不幸的是,虽然这似乎阻止了心跳的发送,但客户端在不发送心跳时仍然会断开连接。

以下内容也不起作用:

io.set('heartbeats', false);

我尝试将某些间隔设置为 0,但没有成功:

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

关于如何正确禁用心跳的任何建议?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

等风也等你 2024-12-10 16:39:59

该代码已

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

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"}]}
吾性傲以野 2024-12-10 16:39:59

心跳有问题。我有最新的 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');
});

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

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.

平定天下 2024-12-10 16:39:59

设置socket.io的日志级别,日志级别为2时,我们看不到每个套接字的所有心跳,只能看到握手和断开连接

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文