我正在创建一个与长轮询一起使用的聊天应用程序,以模拟从服务器到客户端的推送。
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
更多推荐
在没有获得超时的情况下,在响应浏览器之前我可以等待多长时间?
发布评论