Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top