2013-09-05 16:02:48 +02:00
|
|
|
<!--
|
|
|
|
Copyright 2013 IBM Corp.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
-->
|
|
|
|
|
|
|
|
<script type="text/x-red" data-template-name="tcp in">
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-server"><i class="fa fa-dot-circle-o"></i> <span data-i18n="tcpin.label.type"></span></label>
|
2013-09-19 14:01:26 +02:00
|
|
|
<select id="node-input-server" style="width:120px; margin-right:5px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="server" data-i18n="tcpin.type.listen"></option>
|
|
|
|
<option value="client" data-i18n="tcpin.type.connect"></option>
|
2013-09-19 14:01:26 +02:00
|
|
|
</select>
|
2015-05-10 22:47:22 +02:00
|
|
|
<span data-i18n="tcpin.label.port"></span> <input type="text" id="node-input-port" style="width: 50px">
|
2013-09-05 16:02:48 +02:00
|
|
|
</div>
|
2014-07-08 14:45:00 +02:00
|
|
|
<div class="form-row hidden" id="node-input-host-row" style="padding-left: 110px;">
|
2015-05-10 22:47:22 +02:00
|
|
|
<span data-i18n="tcpin.label.host"></span> <input type="text" id="node-input-host" placeholder="localhost" style="width: 60%;">
|
2013-09-05 16:02:48 +02:00
|
|
|
</div>
|
2013-09-19 14:01:26 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.output"></span></label>
|
2013-09-19 14:01:26 +02:00
|
|
|
<select id="node-input-datamode" style="width:110px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="stream" data-i18n="tcpin.output.stream"></option>
|
|
|
|
<option value="single" data-i18n="tcpin.output.single"></option>
|
2013-09-19 14:01:26 +02:00
|
|
|
</select>
|
|
|
|
<select id="node-input-datatype" style="width:140px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="buffer" data-i18n="tcpin.output.buffer"></option>
|
|
|
|
<option value="utf8" data-i18n="tcpin.output.string"></option>
|
|
|
|
<option value="base64" data-i18n="tcpin.output.base64"></option>
|
2013-09-19 14:01:26 +02:00
|
|
|
</select>
|
2015-05-10 22:47:22 +02:00
|
|
|
<span data-i18n="tcpin.label.payload"></span>
|
2013-09-05 16:02:48 +02:00
|
|
|
</div>
|
2013-09-19 14:01:26 +02:00
|
|
|
|
|
|
|
<div id="node-row-newline" class="form-row hidden" style="padding-left: 110px;">
|
2015-05-10 22:47:22 +02:00
|
|
|
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width: 110px;">
|
2013-09-19 14:01:26 +02:00
|
|
|
</div>
|
2014-07-08 14:45:00 +02:00
|
|
|
|
2013-09-05 16:02:48 +02:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-topic"><i class="fa fa-tasks"></i> <span data-i18n="common.label.topic"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-topic" data-i18n="[placeholder]common.label.topic">
|
2013-09-05 16:02:48 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2013-09-05 16:02:48 +02:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="tcp in">
|
2016-02-12 14:17:50 +01:00
|
|
|
<p>Provides a choice of TCP inputs. Can either connect to a remote TCP port,
|
2014-07-08 14:45:00 +02:00
|
|
|
or accept incoming connections.</p>
|
2013-09-05 16:02:48 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('tcp in',{
|
|
|
|
category: 'input',
|
|
|
|
color:"Silver",
|
|
|
|
defaults: {
|
2015-05-26 21:08:58 +02:00
|
|
|
name: {value:""},
|
2013-09-19 14:01:26 +02:00
|
|
|
server: {value:"server",required:true},
|
|
|
|
host: {value:"",validate:function(v) { return (this.server == "server")||v.length > 0;} },
|
2013-09-05 16:02:48 +02:00
|
|
|
port: {value:"",required:true,validate:RED.validators.number()},
|
2013-09-19 14:01:26 +02:00
|
|
|
datamode:{value:"stream"},
|
|
|
|
datatype:{value:"buffer"},
|
|
|
|
newline:{value:""},
|
2013-09-05 16:02:48 +02:00
|
|
|
topic: {value:""},
|
2013-09-19 14:01:26 +02:00
|
|
|
base64: {/*deprecated*/ value:false,required:true}
|
2013-09-05 16:02:48 +02:00
|
|
|
},
|
|
|
|
inputs:0,
|
|
|
|
outputs:1,
|
|
|
|
icon: "bridge-dash.png",
|
|
|
|
label: function() {
|
2013-09-19 14:01:26 +02:00
|
|
|
return this.name || "tcp:"+(this.host?this.host+":":"")+this.port;
|
2013-09-05 16:02:48 +02:00
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
2013-09-19 14:01:26 +02:00
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
var updateOptions = function() {
|
|
|
|
var sockettype = $("#node-input-server option:selected").val();
|
|
|
|
if (sockettype == "client") {
|
|
|
|
$("#node-input-host-row").show();
|
|
|
|
} else {
|
|
|
|
$("#node-input-host-row").hide();
|
|
|
|
}
|
|
|
|
var datamode = $("#node-input-datamode option:selected").val();
|
|
|
|
var datatype = $("#node-input-datatype option:selected").val();
|
|
|
|
if (datamode == "stream") {
|
|
|
|
if (datatype == "utf8") {
|
|
|
|
$("#node-row-newline").show();
|
|
|
|
} else {
|
|
|
|
$("#node-row-newline").hide();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$("#node-row-newline").hide();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
updateOptions();
|
|
|
|
$("#node-input-server").change(updateOptions);
|
|
|
|
$("#node-input-datatype").change(updateOptions);
|
|
|
|
$("#node-input-datamode").change(updateOptions);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2013-11-14 15:39:26 +01:00
|
|
|
|
2014-07-08 14:45:00 +02:00
|
|
|
|
2013-11-14 15:39:26 +01:00
|
|
|
<script type="text/x-red" data-template-name="tcp out">
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-beserver"><i class="fa fa-dot-circle-o"></i> <span data-i18n="tcpin.label.type"></span></label>
|
2013-12-19 22:16:25 +01:00
|
|
|
<select id="node-input-beserver" style="width:150px; margin-right:5px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="server" data-i18n="tcpin.type.listen"></option>
|
|
|
|
<option value="client" data-i18n="tcpin.type.connect"></option>
|
|
|
|
<option value="reply" data-i18n="tcpin.type.reply"></option>
|
2013-11-14 15:39:26 +01:00
|
|
|
</select>
|
2015-05-10 22:47:22 +02:00
|
|
|
<span id="node-input-port-row"><span data-i18n="tcpin.label.port"></span> <input type="text" id="node-input-port" style="width: 50px"></span>
|
2013-11-14 15:39:26 +01:00
|
|
|
</div>
|
2014-07-08 14:45:00 +02:00
|
|
|
|
|
|
|
<div class="form-row hidden" id="node-input-host-row" style="padding-left: 110px;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<span data-i18n="tcpin.label.host"></span> <input type="text" id="node-input-host" style="width: 60%;">
|
2014-09-03 21:06:29 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row hidden" id="node-input-end-row">
|
|
|
|
<label> </label>
|
|
|
|
<input type="checkbox" id="node-input-end" style="display: inline-block; width: auto; vertical-align: top;">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-end" style="width: 70%;"><span data-i18n="tcpin.label.close-connection"></span></label>
|
2013-11-14 15:39:26 +01:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="form-row">
|
|
|
|
<label> </label>
|
|
|
|
<input type="checkbox" id="node-input-base64" placeholder="base64" style="display: inline-block; width: auto; vertical-align: top;">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-base64" style="width: 70%;"><span data-i18n="tcpin.label.decode-base64"></span></label>
|
2013-11-14 15:39:26 +01:00
|
|
|
</div>
|
2014-07-08 14:45:00 +02:00
|
|
|
|
2013-11-14 15:39:26 +01:00
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2013-11-14 15:39:26 +01:00
|
|
|
</div>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="tcp out">
|
2016-02-12 14:17:50 +01:00
|
|
|
<p>Provides a choice of TCP outputs. Can either connect to a remote TCP port,
|
2013-12-19 22:16:25 +01:00
|
|
|
accept incoming connections, or reply to messages received from a TCP In node.</p>
|
2016-02-12 14:17:50 +01:00
|
|
|
<p>Only <code>msg.payload</code> is sent.</p>
|
|
|
|
<p>If <code>msg.payload</code> is a string containing a Base64 encoding of binary
|
2014-07-08 14:45:00 +02:00
|
|
|
data, the Base64 decoding option will cause it to be converted back to binary
|
|
|
|
before being sent.</p>
|
2016-02-12 14:17:50 +01:00
|
|
|
<p>If <code>msg._session</code> is not present the payload is
|
|
|
|
sent to <b>all</b> connected clients.</p>
|
2013-11-14 15:39:26 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('tcp out',{
|
|
|
|
category: 'output',
|
|
|
|
color:"Silver",
|
|
|
|
defaults: {
|
2013-12-19 22:16:25 +01:00
|
|
|
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) } },
|
2013-11-14 15:39:26 +01:00
|
|
|
beserver: {value:"client",required:true},
|
|
|
|
base64: {value:false,required:true},
|
2014-09-03 21:06:29 +02:00
|
|
|
end: {value:false,required:true},
|
2013-11-14 15:39:26 +01:00
|
|
|
name: {value:""}
|
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:0,
|
|
|
|
icon: "bridge-dash.png",
|
|
|
|
align: "right",
|
|
|
|
label: function() {
|
|
|
|
return this.name || "tcp:"+(this.host?this.host+":":"")+this.port;
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return (this.name)?"node_label_italic":"";
|
|
|
|
},
|
|
|
|
oneditprepare: function() {
|
|
|
|
var updateOptions = function() {
|
|
|
|
var sockettype = $("#node-input-beserver option:selected").val();
|
2013-12-19 22:16:25 +01:00
|
|
|
if (sockettype == "reply") {
|
|
|
|
$("#node-input-port-row").hide();
|
|
|
|
$("#node-input-host-row").hide();
|
2014-09-03 21:06:29 +02:00
|
|
|
$("#node-input-end-row").hide();
|
2013-12-19 22:16:25 +01:00
|
|
|
} else {
|
|
|
|
$("#node-input-port-row").show();
|
2014-09-03 21:06:29 +02:00
|
|
|
$("#node-input-end-row").show();
|
2013-12-19 22:16:25 +01:00
|
|
|
}
|
2014-07-08 14:45:00 +02:00
|
|
|
|
2013-11-14 15:39:26 +01:00
|
|
|
if (sockettype == "client") {
|
|
|
|
$("#node-input-host-row").show();
|
|
|
|
} else {
|
|
|
|
$("#node-input-host-row").hide();
|
2014-09-03 21:06:29 +02:00
|
|
|
}
|
2013-11-14 15:39:26 +01:00
|
|
|
};
|
|
|
|
updateOptions();
|
|
|
|
$("#node-input-beserver").change(updateOptions);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
2014-07-08 14:45:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
<script type="text/x-red" data-template-name="tcp request">
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-server"><i class="fa fa-globe"></i> <span data-i18n="tcpin.label.server"></span></label>
|
2014-11-07 13:27:02 +01:00
|
|
|
<input type="text" id="node-input-server" placeholder="ip.address" style="width:45%">
|
2015-05-28 00:07:31 +02:00
|
|
|
port <input type="text" id="node-input-port" style="width:60px">
|
2014-07-08 14:45:00 +02:00
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-out"><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.return"></span></label>
|
2015-05-26 21:08:58 +02:00
|
|
|
<select type="text" id="node-input-out" style="width:56%;">
|
2015-05-28 00:07:31 +02:00
|
|
|
<option value="time" data-i18n="tcpin.return.timeout"></option>
|
|
|
|
<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>
|
2014-07-08 14:45:00 +02:00
|
|
|
</select>
|
|
|
|
<input type="text" id="node-input-splitc" style="width:50px;">
|
|
|
|
<span id="node-units"></span>
|
|
|
|
</div>
|
|
|
|
<div class="form-row">
|
2015-05-10 22:47:22 +02:00
|
|
|
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
|
2015-05-26 22:11:14 +02:00
|
|
|
<input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
|
2014-07-08 14:45:00 +02:00
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
var previous = null;
|
|
|
|
$("#node-input-out").on('focus', function () { previous = this.value; }).change(function() {
|
|
|
|
if (previous == null) { previous = $("#node-input-out").val(); }
|
|
|
|
if ($("#node-input-out").val() == "char") {
|
|
|
|
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");
|
|
|
|
$("#node-units").text("ms");
|
|
|
|
}
|
2014-09-03 21:06:29 +02:00
|
|
|
else if ($("#node-input-out").val() == "count") {
|
2014-07-08 14:45:00 +02:00
|
|
|
if (previous != "count") $("#node-input-splitc").val("12");
|
|
|
|
$("#node-units").text("chars");
|
|
|
|
}
|
2014-09-03 21:06:29 +02:00
|
|
|
else {
|
|
|
|
if (previous != "sit") $("#node-input-splitc").val("0");
|
|
|
|
$("#node-units").text("");
|
|
|
|
}
|
2014-07-08 14:45:00 +02:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/x-red" data-help-name="tcp request">
|
2016-02-12 14:17:50 +01:00
|
|
|
<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
|
2014-07-08 14:45:00 +02:00
|
|
|
returned characters into a fixed buffer, match a specified character before returning,
|
2014-09-03 21:06:29 +02:00
|
|
|
wait a fixed timeout from first reply and then return, or just sit and wait for data.</p>
|
2016-02-12 14:17:50 +01:00
|
|
|
<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>
|
2014-07-08 14:45:00 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script type="text/javascript">
|
|
|
|
RED.nodes.registerType('tcp request',{
|
|
|
|
category: 'function',
|
|
|
|
color:"Silver",
|
|
|
|
defaults: {
|
2014-11-06 11:21:14 +01:00
|
|
|
server: {value:""},
|
|
|
|
port: {value:"",validate:RED.validators.regex(/^(\d*|)$/)},
|
2014-07-08 14:45:00 +02:00
|
|
|
out: {value:"time",required:true},
|
|
|
|
splitc: {value:"0",required:true},
|
|
|
|
name: {value:""}
|
|
|
|
},
|
|
|
|
inputs:1,
|
|
|
|
outputs:1,
|
|
|
|
icon: "bridge-dash.png",
|
|
|
|
label: function() {
|
|
|
|
return this.name || "tcp:"+(this.server?this.server+":":"")+this.port;
|
|
|
|
},
|
|
|
|
labelStyle: function() {
|
|
|
|
return this.name?"node_label_italic":"";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|