谷歌应用程序引擎中通道 API 中的通道断开通知

发布于 2024-12-09 06:23:17 字数 195 浏览 0 评论 0原文

我在手机上使用 GAE 应用程序。即使我通过 socket.close() 函数手动关闭套接字,在通道 api 中获取 /_ah/channel/disconnected 的断开连接通知时也会遇到问题。该帖子会在延迟一分钟后发生。有谁知道加快速度的方法吗?在我的情况下,socket.close() 不会产生通道断开通知(尽管仅在手机中......它在笔记本电脑上完美运行)!

Im using my GAE application on my phone. I face a problem in getting the disconnect notification to /_ah/channel/disconnected in channels api even if i manually close the socket by socket.close() function. the post occurs after a delay of say one minute. Does anyone know the way to speed things up? In my case socket.close() doesnt produce the channel disconnect notification(only in phone though.. it works perfectly from a laptop)!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

呢古 2024-12-16 06:23:17

Channel API 前端服务器“意识到”通道已断开连接所需的时间取决于浏览器的实现。

在行为良好的浏览器上,我们捕获 beforeunload 事件并向前端发布一条消息,表示“此客户端即将消失”。在其他浏览器上,我们可能无法获取事件(或者由于各种实现原因,我们可能无法监听它,例如浏览器发送频率太高(FFFUUUU IE)),或者一旦我们获取事件,我们发送的 XHR 可能会获取吞下去了。在这些情况下,前端服务器意识到客户端已经消失,因为它无法接收到心跳——这就是您手机上发生的情况。 (出于好奇,什么电话?)

您的案例很有趣,因为您明确地调用了 onclose。它所做的唯一事情就是处理具有 Channel FE 代码的 iframe——换句话说,onclose 的行为就像整个浏览器窗口被关闭一样;它没有利用浏览器仍处于良好状态并且可以等待消息发送后关闭的事实。

所以我建议两件事:在代码中添加一个自定义处理程序(与 /_ah/disconnect 处理程序执行相同的操作),这样当您知道要手动关闭通道时,您就可以创建一个 XHR。这是笨拙但实用的。令人遗憾的是,您需要在 JavaScript 代码中明确知道您的客户端 ID。

其次,向我们的问题跟踪器 (http://code.google.com/p/googleappengine/issues/list) 添加一个问题,以便在显式调用 onclose 时请求更好的断开连接通知。

希望有帮助;抱歉,现在没有简单的答案。

The amount of time it takes the Channel API front-end servers to "realize" that a channel is disconnected is contingent on browser implementation.

On well-behaved browsers, we catch the beforeunload event and post a message to our front-end that says, "this client is going away." On other browsers, we may not get the event (or we may not be able to listen to it for various implementation reasons, like the browser sends it too often (FFFUUUU IE)) or once we get the event the XHR we send may get swallowed. In those cases, the frontend server realizes the client is gone because it fails to receive a heartbeat -- this is what's happening on your phone. (out of curiousity, what phone?)

Your case is interesting because you're explicitly calling onclose. The only thing this does is dispose the iframe that has the Channel FE code -- in other words, onclose just behaves as if the whole browser window was closed; it doesn't take advantage of the fact that the browser is still in a good state and could wait to close until a message is sent.

So I recommend two things: add a custom handler to your code (that does the same thing as your /_ah/disconnect handler) so you can just make an XHR when you know you're manually closing the channel. This is kludgy but functional. The bummer about this is you'll need to explicitly know your client id in your javascript code.

Second, add an issue to our issue tracker (http://code.google.com/p/googleappengine/issues/list) to request better disconnect notification when onclose is called explicitly.

Hope that helps; sorry there's not an easy answer right now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文