不同浏览器的超时行为?

发布于 2024-07-29 02:43:44 字数 752 浏览 1 评论 0原文

我正在编写一个基于 AJAX/COMET 的在线聊天室。 我的设计是:

请求

-----------------等待-------------------------> 发送转储数据

-----------------等待-------------------------> 发送转储数据

-----------------等待-------------------------> 发送转储数据

-----------------等待-------------------------> 发送转储数据

-----------------等待-------------------------> 发送转储数据

------发生了事情,得到响应。

另一个请求 …… ....

如您所见,服务器保留请求并等待发生某些事件,如果发生某些事件,则只需推送数据并完成请求。 然后客户端会发出另一个请求。 请求中有勾选,因此如果两个请求之间发生了事件,服务器就知道客户端有待处理的事件。

在浏览器超时之前,服务器也会发送一些空闲数据,以防止客户端超时。

现在,问题来了:不同浏览器的超时行为是什么? 我知道浏览器发送请求并等待数据,如果等待时间太长,就会超时。 但是不同浏览器的超时行为是什么? 是否有任何标头可以控制浏览器的超时行为? 通过了解浏览器的超时行为,以便我可以决定如何处理它们。 我在哪里可以找到这些数据?

I am writing an on line chat room based on AJAX/COMET. My design is:

Request

----------------- wait -------------------------> send dump data

----------------- wait -------------------------> send dump data

----------------- wait -------------------------> send dump data

----------------- wait -------------------------> send dump data

----------------- wait -------------------------> send dump data

------ something happened, get response.

Another request
.....
....

As you see, the server hold the request and wait something happened, if there is some event happened, just push data and finish request. Then the client will issuse another request.
There is tick in request, so if there is event happened betweenhe t gap of two requests, server knows that there is pending event for the client.

Before the browser timeout, the server also send some idle data to prevent client from timeout.

Now, here comes the problem: what are timeout behavior of different browsers? I know that browser sends request and wait for data, if it take too long time to wait, it will timeout. But what are those timeout behavior of different browsers? And are there any header that can control the timeout behavior of browser? By knowing the timeout behavior of browsers, so that I can decide how to deal with them. Where can I find those data?

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

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

发布评论

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

评论(1

风筝有风,海豚有海 2024-08-05 02:43:44

实际上,由于客户端可能会通过代理,因此不同浏览器的显式超时值并不像您想象的那么重要。

相反,我会问你为什么要问 - 你将不得不处理超时,并且浏览器的任何流媒体都不会每次都阻止它。 因此,最好在连接断开时简单地从客户端重新查询服务器 - 这就是很多人建议长轮询的原因之一,而这正是您似乎正在尝试做的事情。 无论您选择流式传输解决方案还是长轮询,都必须允许连接重置。

对于简单的隐藏 iframe 客户端设置,这并不难做到 - XHR 请求同样容易,具体取决于您使用的客户端框架。

大多数现代浏览器的超时似乎相当大 IE(60 分钟?哇),FF 更短(about:config 说 300 秒 - 哎呀)——但正如我所说,这并不能帮助你对抗代理,其中超时可能短至 2 分钟或更短,取决于代理管理员如何配置它。

所以,总而言之 - 超时会发生。 你无法阻止他们。 对您的客户端进行编码,以便在发生这种情况时重新连接(限制以防止服务器停机),并且不必再担心。 除了更加健壮之外,它还可能使您的代码性能更高,因为您不会定期向每个客户端发送无用的数据。

Actually, since the client could be going through proxies, the explicit values of the timeouts for different browsers don't mean as much as you'd think.

Rather, I'd ask why you're asking - you're going to have to deal with timeouts, and no amount of streaming to the browser is going to prevent it every time. So it'd be best to simply requery the server from the client when the connection drops - which is one reason why a lot of people recommend long polling which is what you seem to be trying to do. Regardless of whether you choose a streaming solution or a long poll, you have to allow for connection resets.

For a simple hidden iframe client setup, it's not too hard to do - and it's equally easy for XHR requests, depending on what client side framework you're using.

The timeout for most modern browsers seems to be rather large in IE (60 minutes? Wow), and shorter in FF (about:config says 300 seconds - eek) - but as I said, that doesn't help you against a proxy, where the timeout could be as short as 2 minutes or less, depending on how the proxy admin configured it.

So, in summary - timeouts happen. You can't stop them. Code your client to reconnect when they happen (with a limit to prevent a spin on server down), and don't worry about it further. Besides being more robust, it'll probably also make your code more performant, since you won't be periodically pumping useless data to every client.

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