mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
e574f4516f
commit
b756a8edef
@ -149,7 +149,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
buffer = parts[parts.length-1];
|
buffer = parts[parts.length-1];
|
||||||
} else {
|
} else {
|
||||||
msg = {topic:node.topic, payload:data};
|
msg = {topic:node.topic, payload:data, ip:socket.remoteAddress, port:socket.remotePort};
|
||||||
msg._session = {type:"tcp",id:id};
|
msg._session = {type:"tcp",id:id};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ module.exports = function(RED) {
|
|||||||
socket.on('end', function() {
|
socket.on('end', function() {
|
||||||
if (!node.stream || (node.datatype === "utf8" && node.newline !== "")) {
|
if (!node.stream || (node.datatype === "utf8" && node.newline !== "")) {
|
||||||
if (buffer.length > 0) {
|
if (buffer.length > 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};
|
msg._session = {type:"tcp",id:id};
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
}
|
}
|
||||||
@ -209,7 +209,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("tcp in",TcpIn);
|
RED.nodes.registerType("tcp in",TcpIn);
|
||||||
|
|
||||||
@ -456,16 +455,15 @@ module.exports = function(RED) {
|
|||||||
clients[connection_id].client.on('data', function(data) {
|
clients[connection_id].client.on('data', function(data) {
|
||||||
if (node.out === "sit") { // if we are staying connected just send the buffer
|
if (node.out === "sit") { // if we are staying connected just send the buffer
|
||||||
if (clients[connection_id]) {
|
if (clients[connection_id]) {
|
||||||
|
if (!clients[connection_id].hasOwnProperty("msg")) { clients[connection_id].msg = {}; }
|
||||||
clients[connection_id].msg.payload = data;
|
clients[connection_id].msg.payload = data;
|
||||||
node.send(RED.util.cloneMessage(clients[connection_id].msg));
|
node.send(RED.util.cloneMessage(clients[connection_id].msg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (node.splitc === 0) {
|
else if (node.splitc === 0) {
|
||||||
if (clients[connection_id]) {
|
|
||||||
clients[connection_id].msg.payload = data;
|
clients[connection_id].msg.payload = data;
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
for (var j = 0; j < data.length; j++ ) {
|
for (var j = 0; j < data.length; j++ ) {
|
||||||
if (node.out === "time") {
|
if (node.out === "time") {
|
||||||
@ -483,7 +481,8 @@ module.exports = function(RED) {
|
|||||||
buf.copy(clients[connection_id].msg.payload,0,0,i+1);
|
buf.copy(clients[connection_id].msg.payload,0,0,i+1);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
node.status({}); clients[connection_id].client.destroy();
|
node.status({});
|
||||||
|
clients[connection_id].client.destroy();
|
||||||
delete clients[connection_id];
|
delete clients[connection_id];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -503,7 +502,8 @@ module.exports = function(RED) {
|
|||||||
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
node.status({}); clients[connection_id].client.destroy();
|
node.status({});
|
||||||
|
clients[connection_id].client.destroy();
|
||||||
delete clients[connection_id];
|
delete clients[connection_id];
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -520,7 +520,8 @@ module.exports = function(RED) {
|
|||||||
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
buf.copy(clients[connection_id].msg.payload,0,0,i);
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id].client) {
|
||||||
node.status({}); clients[connection_id].client.destroy();
|
node.status({});
|
||||||
|
clients[connection_id].client.destroy();
|
||||||
delete clients[connection_id];
|
delete clients[connection_id];
|
||||||
}
|
}
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -594,8 +595,10 @@ module.exports = function(RED) {
|
|||||||
this.on("close", function(done) {
|
this.on("close", function(done) {
|
||||||
node.done = done;
|
node.done = done;
|
||||||
for (var client in clients) {
|
for (var client in clients) {
|
||||||
|
if (clients.hasOwnProperty("client")) {
|
||||||
clients[client].client.destroy();
|
clients[client].client.destroy();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
node.status({});
|
node.status({});
|
||||||
|
|
||||||
var anyConnected = false;
|
var anyConnected = false;
|
||||||
|
Loading…
Reference in New Issue
Block a user