From 40f41678944912145f5d32e0f214b8398ee9d48b Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 24 May 2018 21:39:46 +0100 Subject: [PATCH] let TCP in node report remote ip and port when in single packet mode --- nodes/core/io/31-tcpin.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 5853d4f42..c3bc2ab8c 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -130,6 +130,8 @@ module.exports = function(RED) { socket.setKeepAlive(true,120000); if (socketTimeout !== null) { socket.setTimeout(socketTimeout); } var id = (1+Math.random()*4294967295).toString(16); + var fromi; + var fromp; connectionPool[id] = socket; count++; node.status({text:RED._("tcpin.status.connections",{count:count})}); @@ -155,18 +157,21 @@ module.exports = function(RED) { msg._session = {type:"tcp",id:id}; node.send(msg); } - } else { + } + else { if ((typeof data) === "string") { buffer = buffer+data; } else { buffer = Buffer.concat([buffer,data],buffer.length+data.length); } + fromi = socket.remoteAddress; + fromp = socket.remotePort; } }); socket.on('end', function() { if (!node.stream || (node.datatype === "utf8" && node.newline !== "")) { if (buffer.length > 0) { - var msg = {topic:node.topic, payload:buffer, ip:socket.remoteAddress, port:socket.remotePort}; + var msg = {topic:node.topic, payload:buffer, ip:fromi, port:fromp}; msg._session = {type:"tcp",id:id}; node.send(msg); }