Socket Web 应用程序 - 处理移动超时/退出?
假设您有一个 socket.io/node.js 聊天室。如果它在一堆计算机上打开,一切似乎都可以无限期地正常工作。
但假设您已通过手机或平板电脑进行连接,然后走开几分钟。您的移动设备已自动锁定,当您重新打开浏览器时,您在电脑上看到的新消息不存在,并且您尝试发送的消息也不会通过。
是否有任何众所周知的解决方案或解决方法可以使其适合移动用户?
究竟发生了什么? (套接字因移动操作系统超时而关闭?(HTTP 与 TCP 会有所不同吗?))
感谢您的任何见解!
Say you have a socket.io/node.js chatroom. If it's open on a bunch of computers, all seems to work fine indefinitely.
But say you've connected on a phone or tablet, and walk away for a few minutes. Your mobile device has auto-locked and when you reopen your browser, the new messages you see on your PC aren't there and the messages you try and send don't go through.
Is there any well known solution or workaround to making this work well for mobile users?
What exactly is happening? (Socket closed by timeout of mobile os? (would HTTP vs TCP make a difference?))
Thanks for any insights!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
移动浏览器在进入睡眠状态时会停止 javascript 执行,而不会通知 javascript。
您可以使用计时器检测它们何时重新唤醒 任何桌面浏览器都可以检测到计算机何时从睡眠状态恢复吗?
那么您需要重新连接到服务器。
您也可以选择询问浏览器休眠时发生的所有消息。
Mobile browsers stop javascript execution when they go to sleep without informing javascript.
You can detect when they reawaken with a timer Can any desktop browsers detect when the computer resumes from sleep?
Then you need to have reconnect to the server.
Optionally you can ask for all the messages that occurred while the browser was asleep.