Keepalive su nodo tcp

master
Pietro Brenna 2020-04-16 19:00:35 +02:00
parent 2ea5fe3063
commit 0f8107d137
2 changed files with 13 additions and 6 deletions

View File

@ -40,18 +40,22 @@
</select> </select>
<span data-i18n="tcpin.label.payload"></span> <span data-i18n="tcpin.label.payload"></span>
</div> </div>
<div class="form-row">
<label><i class="fa fa-clock-o"></i> <span>Keepalive</span></label>
<input type="text" id="node-input-keepalive" style="text-align:end; width:200px !important">
</div>
<div id="node-row-newline" class="form-row hidden" style="padding-left:110px;"> <div id="node-row-newline" class="form-row hidden" style="padding-left:110px;">
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;"> <span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label> <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
<input type="text" id="node-input-topic" data-i18n="[placeholder]common.label.topic"> <input type="text" id="node-input-topic" placeholder="topic">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label> <label for="node-input-name"><i class="fa fa-tag"></i> <span>Name</span></label>
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name"> <input type="text" id="node-input-name" placeholder="name">
</div> </div>
</script> </script>
@ -67,6 +71,7 @@
datamode: { value: "stream" }, datamode: { value: "stream" },
datatype: { value: "buffer" }, datatype: { value: "buffer" },
newline: { value: "" }, newline: { value: "" },
keepalive: { value: "120000" },
topic: { value: "" }, topic: { value: "" },
base64: {/*deprecated*/ value: false, required: true } base64: {/*deprecated*/ value: false, required: true }
}, },
@ -103,6 +108,7 @@
$("#node-input-server").change(updateOptions); $("#node-input-server").change(updateOptions);
$("#node-input-datatype").change(updateOptions); $("#node-input-datatype").change(updateOptions);
$("#node-input-datamode").change(updateOptions); $("#node-input-datamode").change(updateOptions);
$("#node-input-keepalive").spinner({ min: 1 });
} }
}); });
</script> </script>

View File

@ -55,6 +55,7 @@ module.exports = function(RED) {
this.datatype = n.datatype||'buffer'; /* buffer,utf8,base64 */ this.datatype = n.datatype||'buffer'; /* buffer,utf8,base64 */
this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r"); this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r");
this.base64 = n.base64; this.base64 = n.base64;
this.keepalive = parseInt(n.keepalive) || 120000;
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;
this.connected = false; this.connected = false;
@ -76,7 +77,7 @@ module.exports = function(RED) {
node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port})); node.log(RED._("tcpin.status.connected",{host:node.host,port:node.port}));
node.status({fill:"green",shape:"dot",text:"common.status.connected"}); node.status({fill:"green",shape:"dot",text:"common.status.connected"});
}); });
client.setKeepAlive(true,120000); client.setKeepAlive(true, this.keepalive);
connectionPool[id] = client; connectionPool[id] = client;
client.on('data', function (data) { client.on('data', function (data) {
@ -151,7 +152,7 @@ module.exports = function(RED) {
} }
else { else {
var server = net.createServer(function (socket) { var server = net.createServer(function (socket) {
socket.setKeepAlive(true,120000); socket.setKeepAlive(true, this.keepalive);
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); } if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
var id = (1+Math.random()*4294967295).toString(16); var id = (1+Math.random()*4294967295).toString(16);
var fromi; var fromi;