mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
let TCP in node report remote ip and port when in single packet mode
This commit is contained in:
parent
0ef16989cd
commit
40f4167894
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user