From b756a8edef78280bcfe6010cc5ea3147ba69c78e Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Thu, 20 Apr 2017 12:22:36 +0100 Subject: [PATCH] Make tcp send msg more consistent to close #1236 --- nodes/core/io/31-tcpin.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 776ce942a..8fa30095c 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -63,7 +63,7 @@ module.exports = function(RED) { if ((node.datatype) === "utf8" && node.newline !== "") { buffer = buffer+data; var parts = buffer.split(node.newline); - for (var i = 0;i 0) { - var msg = {topic:node.topic, payload:buffer}; + var msg = {topic:node.topic, payload:buffer, ip:socket.remoteAddress, port:socket.remotePort}; msg._session = {type:"tcp",id:id}; node.send(msg); } @@ -209,7 +209,6 @@ module.exports = function(RED) { } }); } - } RED.nodes.registerType("tcp in",TcpIn); @@ -456,15 +455,14 @@ module.exports = function(RED) { clients[connection_id].client.on('data', function(data) { if (node.out === "sit") { // if we are staying connected just send the buffer if (clients[connection_id]) { + if (!clients[connection_id].hasOwnProperty("msg")) { clients[connection_id].msg = {}; } clients[connection_id].msg.payload = data; node.send(RED.util.cloneMessage(clients[connection_id].msg)); } } else if (node.splitc === 0) { - if (clients[connection_id]) { - clients[connection_id].msg.payload = data; - node.send(clients[connection_id].msg); - } + clients[connection_id].msg.payload = data; + node.send(clients[connection_id].msg); } else { for (var j = 0; j < data.length; j++ ) { @@ -483,7 +481,8 @@ module.exports = function(RED) { buf.copy(clients[connection_id].msg.payload,0,0,i+1); node.send(clients[connection_id].msg); if (clients[connection_id].client) { - node.status({}); clients[connection_id].client.destroy(); + node.status({}); + clients[connection_id].client.destroy(); delete clients[connection_id]; } } @@ -503,7 +502,8 @@ module.exports = function(RED) { buf.copy(clients[connection_id].msg.payload,0,0,i); node.send(clients[connection_id].msg); if (clients[connection_id].client) { - node.status({}); clients[connection_id].client.destroy(); + node.status({}); + clients[connection_id].client.destroy(); delete clients[connection_id]; } i = 0; @@ -520,7 +520,8 @@ module.exports = function(RED) { buf.copy(clients[connection_id].msg.payload,0,0,i); node.send(clients[connection_id].msg); if (clients[connection_id].client) { - node.status({}); clients[connection_id].client.destroy(); + node.status({}); + clients[connection_id].client.destroy(); delete clients[connection_id]; } i = 0; @@ -594,7 +595,9 @@ module.exports = function(RED) { this.on("close", function(done) { node.done = done; for (var client in clients) { - clients[client].client.destroy(); + if (clients.hasOwnProperty("client")) { + clients[client].client.destroy(); + } } node.status({});