From 1ee5e50d501c96fabc35c0f5d49d3f63a9e8ab76 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 20 Oct 2015 10:13:48 +0100 Subject: [PATCH] Turn on tcp node socket keepalive when in server mode --- nodes/core/io/31-tcpin.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 24531a778..e47f29245 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -125,10 +125,12 @@ module.exports = function(RED) { }); } else { var server = net.createServer(function (socket) { + socket.setKeepAlive(true,120000); if (socketTimeout !== null) { socket.setTimeout(socketTimeout); } var id = (1+Math.random()*4294967295).toString(16); connectionPool[id] = socket; - node.status({text:RED._("tcpin.status.connections",{count:++count})}); + count++; + node.status({text:RED._("tcpin.status.connections",{count:count})}); var buffer = (node.datatype == 'buffer')? new Buffer(0):""; socket.on('data', function (data) { @@ -175,7 +177,8 @@ module.exports = function(RED) { }); socket.on('close', function() { delete connectionPool[id]; - node.status({text:RED._("tcpin.status.connections",{count:--count})}); + count--; + node.status({text:RED._("tcpin.status.connections",{count:count})}); }); socket.on('error',function(err) { node.log(err); @@ -303,6 +306,7 @@ module.exports = function(RED) { var connectedSockets = []; node.status({text:RED._("tcpin.status.connections",{count:0})}); var server = net.createServer(function (socket) { + socket.setKeepAlive(true,120000); if (socketTimeout !== null) { socket.setTimeout(socketTimeout); } var remoteDetails = socket.remoteAddress+":"+socket.remotePort; node.log(RED._("tcpin.status.connection-from",{host:socket.remoteAddress, port:socket.remotePort}));