Search code examples
httpcometlong-polling

What is a safe amount of time that I can wait before responding to a browser, without getting a Timeout?


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!


Solution

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