mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix wrong type of string being detected by TCPin node
This commit is contained in:
parent
f0f2a71e3a
commit
56476312c1
@ -30,7 +30,7 @@ function TcpIn(n) {
|
|||||||
this.server = (typeof n.server == 'boolean')?n.server:(n.server == "server");
|
this.server = (typeof n.server == 'boolean')?n.server:(n.server == "server");
|
||||||
this.closing = false;
|
this.closing = false;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
if (!node.server) {
|
if (!node.server) {
|
||||||
var buffer = null;
|
var buffer = null;
|
||||||
var client;
|
var client;
|
||||||
@ -41,13 +41,13 @@ function TcpIn(n) {
|
|||||||
buffer = (node.datatype == 'buffer')? new Buffer(0):"";
|
buffer = (node.datatype == 'buffer')? new Buffer(0):"";
|
||||||
node.log("connected to "+node.host+":"+node.port);
|
node.log("connected to "+node.host+":"+node.port);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('data', function (data) {
|
client.on('data', function (data) {
|
||||||
if (node.datatype != 'buffer') {
|
if (node.datatype != 'buffer') {
|
||||||
data = data.toString(node.datatype);
|
data = data.toString(node.datatype);
|
||||||
}
|
}
|
||||||
if (node.stream) {
|
if (node.stream) {
|
||||||
if ((typeof data) === "string" && node.newline != "") {
|
if ((node.datatype) === "utf8" && node.newline != "") {
|
||||||
buffer = buffer+data;
|
buffer = buffer+data;
|
||||||
var parts = buffer.split(node.newline);
|
var parts = buffer.split(node.newline);
|
||||||
for (var i = 0;i<parts.length-1;i+=1) {
|
for (var i = 0;i<parts.length-1;i+=1) {
|
||||||
@ -100,7 +100,7 @@ function TcpIn(n) {
|
|||||||
if (node.datatype != 'buffer') {
|
if (node.datatype != 'buffer') {
|
||||||
data = data.toString(node.datatype);
|
data = data.toString(node.datatype);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.stream) {
|
if (node.stream) {
|
||||||
if ((typeof data) === "string" && node.newline != "") {
|
if ((typeof data) === "string" && node.newline != "") {
|
||||||
buffer = buffer+data;
|
buffer = buffer+data;
|
||||||
@ -128,21 +128,21 @@ function TcpIn(n) {
|
|||||||
node.send(msg);
|
node.send(msg);
|
||||||
buffer = null;
|
buffer = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.on('error',function(err) {
|
socket.on('error',function(err) {
|
||||||
node.log(err);
|
node.log(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
server.listen(node.port);
|
server.listen(node.port);
|
||||||
node.log('listening on port '+node.port);
|
node.log('listening on port '+node.port);
|
||||||
|
|
||||||
this._close = function() {
|
this._close = function() {
|
||||||
this.closing = true;
|
this.closing = true;
|
||||||
server.close();
|
server.close();
|
||||||
node.log('stopped listening on port '+node.port);
|
node.log('stopped listening on port '+node.port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("tcp in",TcpIn);
|
RED.nodes.registerType("tcp in",TcpIn);
|
||||||
@ -150,4 +150,3 @@ RED.nodes.registerType("tcp in",TcpIn);
|
|||||||
TcpIn.prototype.close = function() {
|
TcpIn.prototype.close = function() {
|
||||||
this._close();
|
this._close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user