Socket.io指定心跳 [英] Socket.io specifying heartbeat

查看:117
本文介绍了Socket.io指定心跳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找出如何为socket.io设置心跳选项?我希望能够指定发生超时"时以及服务器一段时间未收到客户端任何响应时会发生什么.

I can't seem to find out how to set the heartbeat options for socket.io? I'd love to be able to specify what happens when a "timemout" happens, and when the server hasn't gotten any response from the client for some time.

由于某些原因,即使断开连接事件已经过去了一个多小时而没有连接客户端,断开连接事件也不会一直触发.这种情况通常发生在独立的 Java socket.io客户端

For some reason the disconnect event isn't always firing, even though it has passed over an hour without the client not being connected. This often happens with the standalone Java socket.io client

推荐答案

Socket.IO使用engine.io,它允许您指定

Socket.IO uses engine.io, which allows you to specify ping interval and ping timeout, like so:

var app = require('express')();
var http = require('http').Server(app);

var io = require('socket.io')(http, {'pingInterval': 2000, 'pingTimeout': 5000});

(2秒间隔和5秒超时只是一个例子.对于您的用例来说可能很频繁)

(2 second interval and 5 second timeout is just an example. It might be to frequent for your use case)

这篇关于Socket.io指定心跳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆