Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Long polling getting timed out from browser

I'm trying to serve long polling requests for 60 secs using node.js. The problem I'm facing is, the browser is getting timed out. The same setup is working for 30 secs. Can anybody suggest how to achieve this? Using JQuery as JS framework.

Thanks...

like image 309
intellidiot Avatar asked Apr 09 '10 12:04

intellidiot


1 Answers

By default, node.js has a 60 second timeout for TCP/IP connections. You can get around this by explicitly setting the timeout. Here's a quick example:

http.createServer(function (req, res) {
    // Connection now times out after 120 seconds
    req.connection.setTimeout(120000);
    // ... TODO: server logic ...
}).listen(8000);

You can tell node to hold the connection open indefinitely by setting to the timeout to 0. Also, note that the default 60 second timeout applies to all socket connections in addition to TCP/IP.

like image 177
Xavi Avatar answered Sep 18 '22 00:09

Xavi