diff --git a/nodes/core/io/31-tcpin.html b/nodes/core/io/31-tcpin.html index 98fa38ce6..eb294aab2 100644 --- a/nodes/core/io/31-tcpin.html +++ b/nodes/core/io/31-tcpin.html @@ -167,7 +167,7 @@ color:"Silver", defaults: { host: {value:"",validate:function(v) { return (this.beserver != "client")||v.length > 0;} }, - port: {value:"",validate:function(v) { return (this.beserver == "reply")||RED.validators.number()(v) } }, + port: {value:"",validate:function(v) { return (this.beserver == "reply")||RED.validators.number()(v); } }, beserver: {value:"client",required:true}, base64: {value:false,required:true}, end: {value:false,required:true}, @@ -221,8 +221,9 @@ + - +
@@ -235,7 +236,8 @@

A simple TCP request node - sends the msg.payload to a server tcp port and expects a response.

Connects, sends the "request", and reads the "response". It can either count a number of returned characters into a fixed buffer, match a specified character before returning, - wait a fixed timeout from first reply and then return, or just sit and wait for data.

+ wait a fixed timeout from first reply and then return, sit and wait for data, or send then close the connection + immediately, without waiting for a reply.

The response will be output in msg.payload as a buffer, so you may want to .toString() it.

If you leave tcp host or port blank they must be set by using the msg.host and msg.port properties.

Note: Setting a timeout of 0 mS will return immediately and close the connection, without waiting for any reply.

@@ -247,7 +249,7 @@ color:"Silver", defaults: { server: {value:""}, - port: {value:"",validate:RED.validators.regex(/^(\d*|)$/)}, + port: {value:"",validate:RED.validators.regex(/^( \d*|)$/)}, out: {value:"time",required:true}, splitc: {value:"0",required:true}, name: {value:""} @@ -264,21 +266,25 @@ oneditprepare: function() { var previous = null; $("#node-input-out").on('focus', function () { previous = this.value; }).change(function() { - if (previous == null) { previous = $("#node-input-out").val(); } + if (previous === null) { previous = $("#node-input-out").val(); } if ($("#node-input-out").val() == "char") { - if (previous != "char") $("#node-input-splitc").val("\\n"); + if (previous != "char") { $("#node-input-splitc").val("\\n"); } $("#node-units").text(""); } else if ($("#node-input-out").val() == "time") { - if (previous != "time") $("#node-input-splitc").val("0"); + if (previous != "time") { $("#node-input-splitc").val("0"); } $("#node-units").text("ms"); } + else if ($("#node-input-out").val() == "immed") { + if (previous != "immed") { $("#node-input-splitc").val(" "); } + $("#node-units").text(""); + } else if ($("#node-input-out").val() == "count") { - if (previous != "count") $("#node-input-splitc").val("12"); + if (previous != "count") { $("#node-input-splitc").val("12"); } $("#node-units").text("chars"); } else { - if (previous != "sit") $("#node-input-splitc").val("0"); + if (previous != "sit") { $("#node-input-splitc").val("0"); } $("#node-units").text(""); } }); diff --git a/nodes/core/io/31-tcpin.js b/nodes/core/io/31-tcpin.js index d12ec9fc5..c75766032 100644 --- a/nodes/core/io/31-tcpin.js +++ b/nodes/core/io/31-tcpin.js @@ -391,7 +391,8 @@ module.exports = function(RED) { this.out = n.out; this.splitc = n.splitc; - if (this.out != "char") { this.splitc = Number(this.splitc); } + if (this.out === "immed") { this.splitc = -1; this.out = "time"; } + if (this.out !== "char") { this.splitc = Number(this.splitc); } else { if (this.splitc[0] == '\\') { this.splitc = parseInt(this.splitc.replace("\\n",0x0A).replace("\\r",0x0D).replace("\\t",0x09).replace("\\e",0x1B).replace("\\f",0x0C).replace("\\0",0x00)); @@ -445,9 +446,10 @@ module.exports = function(RED) { if (clients[connection_id] && clients[connection_id].client) { clients[connection_id].connected = true; clients[connection_id].client.write(clients[connection_id].msg.payload); - if (node.out === "time" && node.splitc === 0) { - clients[connection_id].client.destroy(); + if (node.out === "time" && node.splitc < 0) { clients[connection_id].connected = false; + clients[connection_id].client.end(); + delete clients[connection_id]; node.status({}); } } @@ -571,7 +573,6 @@ module.exports = function(RED) { node.status({fill:"red",shape:"ring",text:"common.status.error"}); node.error(RED._("tcpin.errors.connect-fail") + " " + connection_id, msg); if (clients[connection_id] && clients[connection_id].client) { - clients[connection_id].connected = false; clients[connection_id].client.destroy(); delete clients[connection_id]; } @@ -601,13 +602,14 @@ module.exports = function(RED) { this.on("close", function(done) { node.done = done; - for (var client in clients) { - if (clients.hasOwnProperty("client")) { - clients[client].client.destroy(); + for (var cl in clients) { + if (clients[cl].hasOwnProperty("client")) { + clients[cl].client.destroy(); } } node.status({}); + // this is probably not necessary and may be removed var anyConnected = false; for (var c in clients) { if (clients[c].connected) { @@ -618,8 +620,8 @@ module.exports = function(RED) { if (!anyConnected) { clients = {}; - done(); } + done(); }); } diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json index f6dd73387..4c6c9d83a 100644 --- a/nodes/core/locales/en-US/messages.json +++ b/nodes/core/locales/en-US/messages.json @@ -417,7 +417,8 @@ "timeout": "after a fixed timeout of", "character": "when character received is", "number": "a fixed number of chars", - "never": "never - keep connection open" + "never": "never - keep connection open", + "immed": "immediately - don't wait for reply" }, "status": { "connecting": "connecting to __host__:__port__",