客户端如何通过离开页面处理socket.io断开连接? [英] How to handle socket.io disconnect by client by leaving page?

查看:92
本文介绍了客户端如何通过离开页面处理socket.io断开连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 node.jssocket.io 应用程序,我想知道有什么可能性可以响应客户端简单地关闭浏览器窗口.无论如何要知道这已经完成了吗?什么样的信号可以发送到服务器?

I have a socket.io application with node.js and was wondering what possibilities exist to respond to a client simply closing their browser window. Is there anyway to know that this has been done? What kinda of signal can been sent to the server?

如果我无法判断某个特定客户端是否已断开连接,我还能做什么?

If I don't have a way of doing telling if a particular client has disconnected what else can I do?

推荐答案

我有一个带有 node.js 的 socket.io 应用程序,我想知道有什么可能性可以简单地关闭浏览器窗口来响应客户端.无论如何要知道这已经完成了吗?什么样的信号可以发送到服务器?

I have a socket.io application with node.js and was wondering what possibilities exist to respond to a client simply closing their browser window. Is there anyway to know that this has been done? What kinda of signal can been sent to the server?

当浏览器关闭连接时,node.js 端的套接字将收到断开连接"事件,然后您可以对此做出反应.

Your socket on the node.js side will receive a "disconnect" event when the browser closes the connection, which you can then react to.

这篇关于客户端如何通过离开页面处理socket.io断开连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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