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:
parent
49389d6f06
commit
6b4e15dd0f
@ -167,7 +167,7 @@
|
|||||||
color:"Silver",
|
color:"Silver",
|
||||||
defaults: {
|
defaults: {
|
||||||
host: {value:"",validate:function(v) { return (this.beserver != "client")||v.length > 0;} },
|
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},
|
beserver: {value:"client",required:true},
|
||||||
base64: {value:false,required:true},
|
base64: {value:false,required:true},
|
||||||
end: {value:false,required:true},
|
end: {value:false,required:true},
|
||||||
@ -221,6 +221,7 @@
|
|||||||
<option value="char" data-i18n="tcpin.return.character"></option>
|
<option value="char" data-i18n="tcpin.return.character"></option>
|
||||||
<option value="count" data-i18n="tcpin.return.number"></option>
|
<option value="count" data-i18n="tcpin.return.number"></option>
|
||||||
<option value="sit" data-i18n="tcpin.return.never"></option>
|
<option value="sit" data-i18n="tcpin.return.never"></option>
|
||||||
|
<option value="immed" data-i18n="tcpin.return.immed"></option>
|
||||||
</select>
|
</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>
|
<span id="node-units"></span>
|
||||||
@ -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>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
|
<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,
|
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>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>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>
|
<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",
|
color:"Silver",
|
||||||
defaults: {
|
defaults: {
|
||||||
server: {value:""},
|
server: {value:""},
|
||||||
port: {value:"",validate:RED.validators.regex(/^(\d*|)$/)},
|
port: {value:"",validate:RED.validators.regex(/^( \d*|)$/)},
|
||||||
out: {value:"time",required:true},
|
out: {value:"time",required:true},
|
||||||
splitc: {value:"0",required:true},
|
splitc: {value:"0",required:true},
|
||||||
name: {value:""}
|
name: {value:""}
|
||||||
@ -264,21 +266,25 @@
|
|||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
var previous = null;
|
var previous = null;
|
||||||
$("#node-input-out").on('focus', function () { previous = this.value; }).change(function() {
|
$("#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 ($("#node-input-out").val() == "char") {
|
||||||
if (previous != "char") $("#node-input-splitc").val("\\n");
|
if (previous != "char") { $("#node-input-splitc").val("\\n"); }
|
||||||
$("#node-units").text("");
|
$("#node-units").text("");
|
||||||
}
|
}
|
||||||
else if ($("#node-input-out").val() == "time") {
|
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");
|
$("#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") {
|
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");
|
$("#node-units").text("chars");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (previous != "sit") $("#node-input-splitc").val("0");
|
if (previous != "sit") { $("#node-input-splitc").val("0"); }
|
||||||
$("#node-units").text("");
|
$("#node-units").text("");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -391,7 +391,8 @@ module.exports = function(RED) {
|
|||||||
this.out = n.out;
|
this.out = n.out;
|
||||||
this.splitc = n.splitc;
|
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 {
|
else {
|
||||||
if (this.splitc[0] == '\\') {
|
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));
|
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) {
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].connected = true;
|
clients[connection_id].connected = true;
|
||||||
clients[connection_id].client.write(clients[connection_id].msg.payload);
|
clients[connection_id].client.write(clients[connection_id].msg.payload);
|
||||||
if (node.out === "time" && node.splitc === 0) {
|
if (node.out === "time" && node.splitc < 0) {
|
||||||
clients[connection_id].client.destroy();
|
|
||||||
clients[connection_id].connected = false;
|
clients[connection_id].connected = false;
|
||||||
|
clients[connection_id].client.end();
|
||||||
|
delete clients[connection_id];
|
||||||
node.status({});
|
node.status({});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -571,7 +573,6 @@ module.exports = function(RED) {
|
|||||||
node.status({fill:"red",shape:"ring",text:"common.status.error"});
|
node.status({fill:"red",shape:"ring",text:"common.status.error"});
|
||||||
node.error(RED._("tcpin.errors.connect-fail") + " " + connection_id, msg);
|
node.error(RED._("tcpin.errors.connect-fail") + " " + connection_id, msg);
|
||||||
if (clients[connection_id] && clients[connection_id].client) {
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].connected = false;
|
|
||||||
clients[connection_id].client.destroy();
|
clients[connection_id].client.destroy();
|
||||||
delete clients[connection_id];
|
delete clients[connection_id];
|
||||||
}
|
}
|
||||||
@ -601,13 +602,14 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
this.on("close", function(done) {
|
this.on("close", function(done) {
|
||||||
node.done = done;
|
node.done = done;
|
||||||
for (var client in clients) {
|
for (var cl in clients) {
|
||||||
if (clients.hasOwnProperty("client")) {
|
if (clients[cl].hasOwnProperty("client")) {
|
||||||
clients[client].client.destroy();
|
clients[cl].client.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.status({});
|
node.status({});
|
||||||
|
|
||||||
|
// this is probably not necessary and may be removed
|
||||||
var anyConnected = false;
|
var anyConnected = false;
|
||||||
for (var c in clients) {
|
for (var c in clients) {
|
||||||
if (clients[c].connected) {
|
if (clients[c].connected) {
|
||||||
@ -618,8 +620,8 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
if (!anyConnected) {
|
if (!anyConnected) {
|
||||||
clients = {};
|
clients = {};
|
||||||
done();
|
|
||||||
}
|
}
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,8 @@
|
|||||||
"timeout": "after a fixed timeout of",
|
"timeout": "after a fixed timeout of",
|
||||||
"character": "when character received is",
|
"character": "when character received is",
|
||||||
"number": "a fixed number of chars",
|
"number": "a fixed number of chars",
|
||||||
"never": "never - keep connection open"
|
"never": "never - keep connection open",
|
||||||
|
"immed": "immediately - don't wait for reply"
|
||||||
},
|
},
|
||||||
"status": {
|
"status": {
|
||||||
"connecting": "connecting to __host__:__port__",
|
"connecting": "connecting to __host__:__port__",
|
||||||
|
Loading…
Reference in New Issue
Block a user