nodejs websocket检测断开连接的套接字 [英] nodejs websocket detect disconnected socket

查看:1186
本文介绍了nodejs websocket检测断开连接的套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个nodejs websocket服务器,我有以下问题。

I have a nodejs websocket server and I have the following problem.

当我的客户端连接到服务器并正常终止 onclose <在这些套接字上调用/ code>方法,并在关闭的套接字上执行清理操作。

When my clients connect to the server and terminate gracefully the onclose method is called on those sockets and I perform clean up operations on the closed socket.

当客户端由于网络而断开连接时, onclose 方法未被调用。是否有任何超时设置,因此超时后会自动调用 onclose

When the client disconnects due to network, the onclose method is not called. Is there any timeout to be set so onclose is called automatically after a timeout?

我正在使用 ws 包nodejs中的websocket服务器

I am using ws package for the websocket server in nodejs

推荐答案

默认ws实现没有从客户端断开网络连接的回调

default ws implementation doesn't have a callback for network disconnects from client side

你可以找到一个keepAlive实现这里

You can find a keepAlive implementation here

这篇关于nodejs websocket检测断开连接的套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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