服务器本身的 Socket IO jquery 事件
当用户断开连接时,我正在尝试找到一种更新社交网络数据库的好方法,因为用户不再在网站上,因此无法激活脚本来更新数据库,并向网站上的其他用户发出事件站点,所以我想我需要知道如何在服务器本身上执行此操作,而不是依赖客户端脚本。
现在我正在脚本的服务器端部分执行类似的操作(仍然由用户加载),
socket.on('disconnect', function () {
socket.broadcast.emit('disconnect', { data : session});
});
然后再次触发用户端脚本上的事件,并运行 ajax 事件来更新 MYSQL 数据库,然后触发另一个套接字事件发送给用户,通知该用户已断开连接,但这仅在用户关闭浏览器时才起作用,但不像关闭笔记本电脑或任何设备那样有效,并且它还依赖于发送给其他用户让他们来处理它,这我不可能发生这样的事
这让我很困扰,我需要想出一个解决办法。
I'm trying to get a good way of updating the database for my social network when users disconnect, since the user is no longer on the site there scripts can't be activated to update the database, and emit events to other users on the site, so I'm thinking that I need to some how do this on the server itself, rather than relying on the client side scripting.
right now I'm doing something like this on the server side part of the scripting, (which is loaded by the user still)
socket.on('disconnect', function () {
socket.broadcast.emit('disconnect', { data : session});
});
this then triggers the event on the user side scripting again, and it runs an ajax event to update the MYSQL database, and then trigger another socket event to send to the users notifying that this user disconnected, however this only works if the user closes their browser, but not like shut their laptop, or whatever device, and it also relies on being sent to other users for them to handle it, which I can't have happening.
This is troubling me very much, I need to come up with a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用ajax轮询(不断发送服务器监听的ajax请求并允许10秒后超时)来表明用户仍然在线。当服务器停止接收请求时,用户已注销。
Use ajax polling (continually send ajax reqeusts which the server listens to and allows to timeout after 10 seconds) to signal that user is still online. When the server stops receiving requests, the user has logged out.