Long browser polling

I am trying to use long polling requests for 60 seconds using node.js. The problem I encountered is the browser timeout. The same setting works for 30 seconds. Can anyone suggest how to achieve this? Using jQuery as a JS infrastructure.

Thanks...

+4
source share
1 answer

By default, node.js has a 60 second timeout for TCP / IP connections. You can get around this by explicitly setting a timeout . Here is 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 say that node can hold the connection indefinitely by setting the timeout value to 0. Also note that the 60 second timeout is applied by default to all socket connections in addition to TCP / IP.

+4
source

Source: https://habr.com/ru/post/1306472/


All Articles