在没有获得超时的情况下,在响应浏览器之前我可以等待多长时间?

编程入门 行业动态 更新时间:2024-10-26 14:31:59
本文介绍了在没有获得超时的情况下,在响应浏览器之前我可以等待多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在创建一个与长轮询一起使用的聊天应用程序,以模拟从服务器到客户端的推送。

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.

现在,如果30秒过去了,我还没有发送任何东西,那么我做发送回复,基本上说NoNews,客户端将再次进行投票。

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?

谢谢!

推荐答案

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

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

更新:

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

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..

  • ajaxpatterns/XMLHttpRequest_Call
  • geekswithblogs/lorint/archive/2006/03/07/71625.aspx
  • http:// ajaxblog/archives/2005/06/01/async-requests-over-an-unreliable-network
  • ajaxpatterns/XMLHttpRequest_Call
  • geekswithblogs/lorint/archive/2006/03/07/71625.aspx
  • ajaxblog/archives/2005/06/01/async-requests-over-an-unreliable-network

更多推荐

在没有获得超时的情况下,在响应浏览器之前我可以等待多长时间?

本文发布于:2023-11-24 21:30:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1626915.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多长时间   情况下   浏览器

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!