1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

fix tcp port not waiting as per info/previous behaviour

add separate return immediate mode rather than conflate ideas
This commit is contained in:
Dave Conway-Jones 2017-05-11 17:24:20 +01:00
parent 49389d6f06
commit 6b4e15dd0f
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
3 changed files with 27 additions and 18 deletions

View File

@ -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 @@
<option value="char" data-i18n="tcpin.return.character"></option>
<option value="count" data-i18n="tcpin.return.number"></option>
<option value="sit" data-i18n="tcpin.return.never"></option>
<option value="immed" data-i18n="tcpin.return.immed"></option>
</select>
<input type="text" id="node-input-splitc" style="width:50px;">
<input type="text" id="node-input-splitc" style="width:50px;">
<span id="node-units"></span>
</div>
<div class="form-row">
@ -235,7 +236,8 @@
<p>A simple TCP request node - sends the <code>msg.payload</code> to a server tcp port and expects a response.</p>
<p>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.</p>
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.</p>
<p>The response will be output in <code>msg.payload</code> as a buffer, so you may want to .toString() it.</p>
<p>If you leave tcp host or port blank they must be set by using the <code>msg.host</code> and <code>msg.port</code> properties.</p>
<p><b>Note: </b>Setting a timeout of 0 mS will return immediately and close the connection, without waiting for any reply.</p>
@ -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("");
}
});

View File

@ -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();
});
}

View File

@ -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__",