From 4f174308b999e83b4090da95a637d6727ae43033 Mon Sep 17 00:00:00 2001 From: dceejay Date: Tue, 26 May 2015 20:08:58 +0100 Subject: [PATCH] Fix tcp node miscounting bytes, and check if staying connected first. --- nodes/core/io/31-tcpin.html | 4 ++-- nodes/core/io/31-tcpin.js | 42 ++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/nodes/core/io/31-tcpin.html b/nodes/core/io/31-tcpin.html index d20a84822..f7a0ac2de 100644 --- a/nodes/core/io/31-tcpin.html +++ b/nodes/core/io/31-tcpin.html @@ -66,6 +66,7 @@ category: 'input', color:"Silver", defaults: { + name: {value:""}, server: {value:"server",required:true}, host: {value:"",validate:function(v) { return (this.server == "server")||v.length > 0;} }, port: {value:"",required:true,validate:RED.validators.number()}, @@ -73,7 +74,6 @@ datatype:{value:"buffer"}, newline:{value:""}, topic: {value:""}, - name: {value:""}, base64: {/*deprecated*/ value:false,required:true} }, inputs:0, @@ -229,7 +229,7 @@
- diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index 71498d7e9..fb492a54b 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -1,5 +1,5 @@ /** - * Copyright 2013,2014 IBM Corp. + * Copyright 2013,2015 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -84,7 +84,7 @@ module.exports = function(RED) { }); client.on('end', function() { if (!node.stream || (node.datatype == "utf8" && node.newline != "" && buffer.length > 0)) { - var msg = {topic:node.topic,payload:buffer}; + var msg = {topic:node.topic, payload:buffer}; msg._session = {type:"tcp",id:id}; if (buffer.length !== 0) { end = true; // only ask for fast re-connect if we actually got something @@ -141,13 +141,13 @@ module.exports = function(RED) { 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}; msg._session = {type:"tcp",id:id}; node.send(msg); } @@ -236,7 +236,7 @@ module.exports = function(RED) { node.status({fill:"green",shape:"dot",text:"connected"}); }); client.on('error', function (err) { - node.log('error : '+err); + node.log(err); }); client.on('end', function (err) { }); @@ -334,7 +334,7 @@ module.exports = function(RED) { } else { buffer = new Buffer(""+msg.payload); } - for (var i = 0; i= node.serialConfig.count) { - node.send({"payload": buf}); + if ( i >= node.splitc) { + m = new Buffer(i); + buf.copy(m,0,0,i); if (client) { client.end(); } i = 0; } @@ -453,11 +455,9 @@ module.exports = function(RED) { buf[i] = data[j]; i += 1; if (data[j] == node.splitc) { - var m = new Buffer(i); + m = new Buffer(i); buf.copy(m,0,0,i); - node.send({"payload": m}); if (client) { client.end(); } - m = null; i = 0; } } @@ -466,9 +466,9 @@ module.exports = function(RED) { }); client.on('end', function() { - //node.log('client disconnected'); node.connected = false; node.status({}); + node.send({"payload":m}); client = null; });