[CCSDK-28] populated the seed code for dgbuilder
[ccsdk/distribution.git] / dgbuilder / core_nodes / io / 31-tcpin.html
1 <!--
2   Copyright 2013 IBM Corp.
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8   http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 -->
16
17 <script type="text/x-red" data-template-name="tcp in">
18     <div class="form-row">
19         <label for="node-input-server"><i class="fa fa-dot-circle-o"></i> Type</label>
20         <select id="node-input-server" style="width:120px; margin-right:5px;">
21             <option value="server">Listen on</option>
22             <option value="client">Connect to</option>
23         </select>
24         port <input type="text" id="node-input-port" style="width: 50px">
25     </div>
26     <div class="form-row hidden" id="node-input-host-row" style="padding-left: 110px;">
27         at host <input type="text" id="node-input-host" placeholder="localhost" style="width: 60%;">
28     </div>
29
30     <div class="form-row">
31         <label><i class="fa fa-sign-out"></i> Output</label>
32         a
33         <select id="node-input-datamode" style="width:110px;">
34             <option value="stream">stream of</option>
35             <option value="single">single</option>
36         </select>
37         <select id="node-input-datatype" style="width:140px;">
38             <option value="buffer">Buffer</option>
39             <option value="utf8">String</option>
40             <option value="base64">Base64 String</option>
41         </select>
42         payload<span id="node-input-datamode-plural">s</span>
43     </div>
44
45     <div id="node-row-newline" class="form-row hidden" style="padding-left: 110px;">
46         delimited by <input type="text" id="node-input-newline" style="width: 110px;">
47     </div>
48
49     <div class="form-row">
50         <label for="node-input-topic"><i class="fa fa-tasks"></i> Topic</label>
51         <input type="text" id="node-input-topic" placeholder="Topic">
52     </div>
53     <div class="form-row">
54         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
55         <input type="text" id="node-input-name" placeholder="Name">
56     </div>
57 </script>
58
59 <script type="text/x-red" data-help-name="tcp in">
60     <p>Provides a choice of tcp inputs. Can either connect to a remote tcp port,
61        or accept incoming connections.</p>
62 </script>
63
64 <script type="text/javascript">
65     RED.nodes.registerType('tcp in',{
66         category: 'input',
67         color:"Silver",
68         defaults: {
69             server: {value:"server",required:true},
70             host: {value:"",validate:function(v) { return (this.server == "server")||v.length > 0;} },
71             port: {value:"",required:true,validate:RED.validators.number()},
72             datamode:{value:"stream"},
73             datatype:{value:"buffer"},
74             newline:{value:""},
75             topic: {value:""},
76             name: {value:""},
77             base64: {/*deprecated*/ value:false,required:true}
78         },
79         inputs:0,
80         outputs:1,
81         icon: "bridge-dash.png",
82         label: function() {
83             return this.name || "tcp:"+(this.host?this.host+":":"")+this.port;
84         },
85         labelStyle: function() {
86             return this.name?"node_label_italic":"";
87         },
88         oneditprepare: function() {
89             var updateOptions = function() {
90                 var sockettype = $("#node-input-server option:selected").val();
91                 if (sockettype == "client") {
92                     $("#node-input-host-row").show();
93                 } else {
94                     $("#node-input-host-row").hide();
95                 }
96                 var datamode = $("#node-input-datamode option:selected").val();
97                 var datatype = $("#node-input-datatype option:selected").val();
98                 if (datamode == "stream") {
99                     $("#node-input-datamode-plural").show();
100                     if (datatype == "utf8") {
101                         $("#node-row-newline").show();
102                     } else {
103                         $("#node-row-newline").hide();
104                     }
105                 } else {
106                     $("#node-input-datamode-plural").hide();
107                     $("#node-row-newline").hide();
108                 }
109             };
110             updateOptions();
111             $("#node-input-server").change(updateOptions);
112             $("#node-input-datatype").change(updateOptions);
113             $("#node-input-datamode").change(updateOptions);
114         }
115     });
116 </script>
117
118
119 <script type="text/x-red" data-template-name="tcp out">
120     <div class="form-row">
121         <label for="node-input-beserver"><i class="fa fa-dot-circle-o"></i> Type</label>
122         <select id="node-input-beserver" style="width:150px; margin-right:5px;">
123             <option value="server">Listen on</option>
124             <option value="client">Connect to</option>
125             <option value="reply">Reply to TCP</option>
126         </select>
127         <span id="node-input-port-row">port <input type="text" id="node-input-port" style="width: 50px"></span>
128     </div>
129
130     <div class="form-row hidden" id="node-input-host-row" style="padding-left: 110px;">
131         at host <input type="text" id="node-input-host" placeholder="localhost" style="width: 60%;">
132     </div>
133
134     <div class="form-row hidden" id="node-input-end-row">
135         <label>&nbsp;</label>
136         <input type="checkbox" id="node-input-end" style="display: inline-block; width: auto; vertical-align: top;">
137         <label for="node-input-end" style="width: 70%;">Close connection after each message is sent ?</label>
138     </div>
139
140     <div class="form-row">
141         <label>&nbsp;</label>
142         <input type="checkbox" id="node-input-base64" placeholder="base64" style="display: inline-block; width: auto; vertical-align: top;">
143         <label for="node-input-base64" style="width: 70%;">Decode Base64 message ?</label>
144     </div>
145
146     <div class="form-row">
147         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
148         <input type="text" id="node-input-name" placeholder="Name">
149     </div>
150
151     <div class="form-tips hidden" id="fin-tip">
152         <b>Note:</b> Closing the connection after each message is generally not a good thing - but is useful to indicate an end-of-file for example.
153     </div>
154     <div class="form-tips hidden" id="fin-tip2">
155         <b>Note:</b> Closing the connection after each message is generally not a good thing - but is useful to indicate an end-of-file for example. The receiving client will need to reconnect.
156     </div>
157 </script>
158
159 <script type="text/x-red" data-help-name="tcp out">
160     <p>Provides a choice of tcp outputs. Can either connect to a remote tcp port,
161     accept incoming connections, or reply to messages received from a TCP In node.</p>
162     <p>Only <b>msg.payload</b> is sent.</p>
163     <p>If <b>msg.payload</b> is a string containing a Base64 encoding of binary
164     data, the Base64 decoding option will cause it to be converted back to binary
165     before being sent.</p>
166 </script>
167
168 <script type="text/javascript">
169     RED.nodes.registerType('tcp out',{
170         category: 'output',
171         color:"Silver",
172         defaults: {
173             host: {value:"",validate:function(v) { return (this.beserver != "client")||v.length > 0;} },
174             port: {value:"",validate:function(v) { return (this.beserver == "reply")||RED.validators.number()(v) } },
175             beserver: {value:"client",required:true},
176             base64: {value:false,required:true},
177             end: {value:false,required:true},
178             name: {value:""}
179         },
180         inputs:1,
181         outputs:0,
182         icon: "bridge-dash.png",
183         align: "right",
184         label: function() {
185             return this.name || "tcp:"+(this.host?this.host+":":"")+this.port;
186         },
187         labelStyle: function() {
188             return (this.name)?"node_label_italic":"";
189         },
190         oneditprepare: function() {
191             var updateOptions = function() {
192                 var sockettype = $("#node-input-beserver option:selected").val();
193                 if (sockettype == "reply") {
194                     $("#node-input-port-row").hide();
195                     $("#node-input-host-row").hide();
196                     $("#node-input-end-row").hide();
197                 } else {
198                     $("#node-input-port-row").show();
199                     $("#node-input-end-row").show();
200                 }
201
202                 if (sockettype == "client") {
203                     $("#node-input-host-row").show();
204                     $("#fin-tip").show();
205                 } else {
206                     $("#node-input-host-row").hide();
207                     $("#fin-tip").hide();
208                 }
209
210                 if (sockettype == "server") {
211                     $("#fin-tip2").show();
212                 }
213                 else {
214                     $("#fin-tip2").hide();
215                 }
216
217             };
218             updateOptions();
219             $("#node-input-beserver").change(updateOptions);
220         }
221     });
222 </script>
223
224
225 <script type="text/x-red" data-template-name="tcp request">
226     <div class="form-row">
227         <label for="node-input-server"><i class="fa fa-globe"></i> Server</label>
228         <input type="text" id="node-input-server" placeholder="ip.address" style="width:50%">
229         &nbsp;port <input type="text" id="node-input-port" style="width:50px">
230     </div>
231     <div class="form-row">
232         <label for="node-input-out"><i class="fa fa-sign-out"></i> Return</label>
233         <select type="text" id="node-input-out" style="width:52%;">
234             <option value="time">after a fixed timeout of</option>
235             <option value="char">when character received is</option>
236             <option value="count">a fixed number of characters</option>
237             <option value="sit">never. Keep connection open</option>
238         </select>
239         <input type="text" id="node-input-splitc"  style="width:50px;">
240         <span id="node-units"></span>
241     </div>
242     <div class="form-row">
243         <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
244         <input type="text" id="node-input-name" placeholder="Name">
245     </div>
246     <div class="form-tips"><b>Tip:</b> outputs a binary <b>Buffer</b>, so you may want to .toString() it.</div>
247     <script>
248         var previous = null;
249         $("#node-input-out").on('focus', function () { previous = this.value; }).change(function() {
250             if (previous == null) { previous = $("#node-input-out").val(); }
251             if ($("#node-input-out").val() == "char") {
252                 if (previous != "char") $("#node-input-splitc").val("\\n");
253                 $("#node-units").text("");
254             }
255             else if ($("#node-input-out").val() == "time") {
256                 if (previous != "time") $("#node-input-splitc").val("0");
257                 $("#node-units").text("ms");
258             }
259             else if ($("#node-input-out").val() == "count") {
260                 if (previous != "count") $("#node-input-splitc").val("12");
261                 $("#node-units").text("chars");
262             }
263             else {
264                 if (previous != "sit") $("#node-input-splitc").val("0");
265                 $("#node-units").text("");
266             }
267         });
268 </script>
269
270 <script type="text/x-red" data-help-name="tcp request">
271     <p>A simple TCP request node - sends the <b>msg.payload</b> to a server tcp port and expects a response.</p>
272     <p>Connects, sends the "request", reads the "response". It can either count a number of
273     returned characters into a fixed buffer, match a specified character before returning,
274     wait a fixed timeout from first reply and then return, or just sit and wait for data.</p>
275     <p>The response will be output in <b>msg.payload</b> as a buffer, so you may want to .toString() it.</p>
276 </script>
277
278 <script type="text/javascript">
279     RED.nodes.registerType('tcp request',{
280         category: 'function',
281         color:"Silver",
282         defaults: {
283             server: {value:"",required:true},
284             port: {value:"",required:true,validate:RED.validators.number()},
285             out: {value:"time",required:true},
286             splitc: {value:"0",required:true},
287             name: {value:""}
288         },
289         inputs:1,
290         outputs:1,
291         icon: "bridge-dash.png",
292         label: function() {
293             return this.name || "tcp:"+(this.server?this.server+":":"")+this.port;
294         },
295         labelStyle: function() {
296             return this.name?"node_label_italic":"";
297         }
298     });
299 </script>