在响应浏览器之前可以等待多长时间而不会超时?

发布于 2024-08-03 05:50:36 字数 334 浏览 2 评论 0原文

我正在制作一个聊天应用程序,它使用长轮询来模拟从服务器到客户端的“推送”。

基本上,浏览器会要求更新,如果有新内容我就会回复。否则,我会保持连接打开而不响应,直到有东西要发回为止。

现在,如果 30 秒过去了并且我还没有发送任何内容,那么我会发送一个响应,基本上说“NoNews”,然后客户端将再次轮询。

我想做的显然是尽可能长时间地保持此连接而不回复,然后浏览器就会超时并放弃我...... 我还没有找到关于每个浏览器的客户端超时的详细文档,而且似乎所有浏览器的客户端超时都不相同...

你们有人制作过长轮询应用程序吗?
你知道最长的安全超时可能是多少吗?

谢谢!

I'm making a chat application that works with long-polling to emulate a "push" from server to client.

Basically, the browser asks for updates, and I reply if there's something new. Otherwise, I keep the connection open without responding until there is something to send back.

Now, if 30 seconds have passed and I haven't sent anything, then I do send a response, saying basically "NoNews", and the client will poll again.

What I want to do is obviously keep this connection without replying for as long as possible, before the browser will simply time out and give up on me...
I haven't found good documentation on what the Client Timeout is for each browser, and it doesn't seem like it's the same for all of them...

Has any of you made a long-polling application?
Any ideas what the longest safe timeout might be?

Thanks!

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

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

发布评论

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

评论(2

一个人的夜不怕黑 2024-08-10 05:50:36

浏览器应检测 XHR 超时并发出另一个请求。

更新:

检测 XHR 上的超时实际上很复杂,因为由于某种原因它不是内置的。当然,您还需要处理 502/503 响应等。

The browser should detect a timeout on an XHR and make another request.

Update:

Detecting timeouts on an XHR is actually complicated, since it's not built-in for some reason. Of course you will also need to handle 502/503 responses, etc..

素衣风尘叹 2024-08-10 05:50:36

读取超时因浏览器而异。例如,这些是 IE 的默认值,

Internet Explorer 4.0 and Internet Explorer 4.01 - 5 minutes
Internet Explorer 5.x and Internet Explorer 6.x - 60 minutes
Internet Explorer 7 and Internet Explorer 8 - 60 minutes

正如您所看到的,随着时间的推移它会变得更大。

在长轮询中,超时是你的朋友。你应该利用它,而不是回避它。超时意味着您正在使用浏览器进行最长的轮询。超时是一个即使没有长轮询也必须处理的错误,因此没有额外的负担。

您可能想阅读我对此问题的回答,

从 J2ME 客户端轮询 HTTP 服务器< /a>

即使它适用于移动客户端,大多数规则也适用于 AJAX 长轮询。具体来说,我认为您将从通知系统中受益,因此长轮询仅用于事件通知,并且所有内容仍然正常拉取。

The read timeout varies between browsers. For example, these are default values for IE,

Internet Explorer 4.0 and Internet Explorer 4.01 - 5 minutes
Internet Explorer 5.x and Internet Explorer 6.x - 60 minutes
Internet Explorer 7 and Internet Explorer 8 - 60 minutes

As you can see, it gets larger overtime.

In long polling, timeout is your friend. You should take advantage of it, instead of avoiding it. Timeout means you are doing LONGEST polling possible with the browser. Timeout is an error you have to handle even without long polling so there is no extra burden.

You might want read my response to this question,

polling a HTTP server from J2ME client

Even though it's for a mobile client, most rules apply to AJAX long polling also. Specifically, I think you will benefit from a notification system so long polling is only used for event notification and all contents are still pulled normally.

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