From 0968f969822b9185a014aec761bc5fc8c28d2237 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Tue, 6 Feb 2018 11:36:09 +0000 Subject: [PATCH] add a default keepalive to tcp client mode to address #1469 --- nodes/core/io/31-tcpin.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 607879cb8..5853d4f42 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -52,6 +52,7 @@ module.exports = function(RED) { node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port})); node.status({fill:"green",shape:"dot",text:"common.status.connected"}); }); + client.setKeepAlive(true,120000); connectionPool[id] = client; client.on('data', function (data) { @@ -123,7 +124,8 @@ module.exports = function(RED) { clearTimeout(reconnectTimeout); if (!node.connected) { done(); } }); - } else { + } + else { var server = net.createServer(function (socket) { socket.setKeepAlive(true,120000); if (socketTimeout !== null) { socket.setTimeout(socketTimeout); } @@ -184,6 +186,7 @@ module.exports = function(RED) { node.log(err); }); }); + server.on('error', function(err) { if (err) { node.error(RED._("tcpin.errors.cannot-listen",{port:node.port,error:err.toString()})); @@ -237,6 +240,7 @@ module.exports = function(RED) { node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port})); node.status({fill:"green",shape:"dot",text:"common.status.connected"}); }); + client.setKeepAlive(true,120000); client.on('error', function (err) { node.log(RED._("tcpin.errors.error",{error:err.toString()})); }); @@ -288,7 +292,8 @@ module.exports = function(RED) { if (!node.connected) { done(); } }); - } else if (node.beserver == "reply") { + } + else if (node.beserver == "reply") { node.on("input",function(msg) { if (msg._session && msg._session.type == "tcp") { var client = connectionPool[msg._session.id]; @@ -314,7 +319,8 @@ module.exports = function(RED) { } } }); - } else { + } + else { var connectedSockets = []; node.status({text:RED._("tcpin.status.connections",{count:0})}); var server = net.createServer(function (socket) {