Does socket.io handle keepalives automatically?

kojow7 picture kojow7 · Oct 25, 2016 · Viewed 9.3k times · Source

I am using node.js and socket.io on a Linode server. I was told that I should use KeepAlives with my app in order to make use of a Linode NodeBalancer. I was also told that I had to set the NodeBalancer protocol to use TCP rather than (HTTP or HTTPS which both disable KeepAlives).

My question is, are KeepAlives already implemented in socket.io by default? There seems to be something keeping the connection alive so I am thinking that this is already handled by socket.io. However, I cannot seem to find any info on this topic. If KeepAlives are not implemented by default in socket.io what problems will I face using the NodeBalancer? If I should be implementing KeepAlives what steps do I need to take to implement them in my app?

As an additional question, if KeepAlives are implemented in socket.io, what issues will I face if I use the HTTP option rather than TCP?

Answer

Denis Lisitskiy picture Denis Lisitskiy · Oct 25, 2016

Yes. And you can set options.

var myApp = require('express')();
var http = require('http').Server(myApp);

var io = require('socket.io')(http, {'pingTimeout': 7000, 'pingInterval': 3000});