2 Copyright 2013 IBM Corp.
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
8 http://www.apache.org/licenses/LICENSE-2.0
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.
17 <!-- The Input Node -->
18 <script type="text/x-red" data-template-name="udp in">
19 <div class="form-row">
20 <label for="node-input-port"><i class="fa fa-sign-in"></i> Listen</label>
21 on port <input type="text" id="node-input-port" placeholder="Port" style="width: 45px">
22 for <select id="node-input-multicast" style='width:40%'>
23 <option value="false">udp messages</option>
24 <option value="true">multicast messages</option>
27 <div class="form-row node-input-group">
28 <label for="node-input-group"><i class="fa fa-list"></i> Group</label>
29 <input type="text" id="node-input-group" placeholder="225.0.18.83">
31 <div class="form-row node-input-iface">
32 <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
33 <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
35 <div class="form-row">
36 <label for="node-input-datatype"><i class="fa fa-sign-out"></i> Output</label>
37 <select id="node-input-datatype" style="width: 70%;">
38 <option value="buffer">a Buffer</option>
39 <option value="utf8">a String</option>
40 <option value="base64">a Base64 encoded string</option>
43 <div class="form-row">
44 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
45 <input type="text" id="node-input-name" placeholder="Name">
47 <div class="form-tips">Tip: Make sure your firewall will allow the data in.</div>
49 $("#node-input-multicast").change(function() {
50 var id = $("#node-input-multicast option:selected").val();
52 $(".node-input-group").hide();
53 $(".node-input-iface").hide();
56 $(".node-input-group").show();
57 $(".node-input-iface").show();
63 <script type="text/x-red" data-help-name="udp in">
64 <p>A udp input node, that produces a <b>msg.payload</b> containing a <i>BUFFER</i>, string, or base64 encoded string. Supports multicast.</p>
65 <p>It also provides <b>msg.ip</b> and <b>msg.port</b> to the ip address and port from which the message was received.</p>
66 <p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
69 <script type="text/javascript">
70 RED.nodes.registerType('udp in',{
76 port: {value:"",required:true,validate:RED.validators.number()},
77 datatype: {value:"buffer",required:true},
78 multicast: {value:"false"},
79 group: {value:"",validate:function(v) { return (this.multicast !== "true")||v.length > 0;} }
83 icon: "bridge-dash.png",
85 if (this.multicast=="false") {
86 return this.name||"udp "+this.port;
88 else return this.name||"udp "+(this.group+":"+this.port);
90 labelStyle: function() {
91 return this.name?"node_label_italic":"";
97 <!-- The Output Node -->
98 <script type="text/x-red" data-template-name="udp out">
99 <div class="form-row">
100 <label for="node-input-port"><i class="fa fa-envelope"></i> Send a</label>
101 <select id="node-input-multicast" style='width:40%'>
102 <option value="false">udp message</option>
103 <option value="broad">broadcast message</option>
104 <option value="multi">multicast message</option>
106 to port <input type="text" id="node-input-port" placeholder="port" style="width: 70px">
108 <div class="form-row node-input-addr">
109 <label for="node-input-addr" id="node-input-addr-label"><i class="fa fa-list"></i> Address</label>
110 <input type="text" id="node-input-addr" placeholder="destination ip" style="width: 70%;">
112 <div class="form-row node-input-iface">
113 <label for="node-input-iface"><i class="fa fa-random"></i> Interface</label>
114 <input type="text" id="node-input-iface" placeholder="(optional) ip address of eth0">
116 <div class="form-row">
117 <label for="node-input-outport-type"> </label>
118 <select id="node-input-outport-type">
119 <option id="node-input-outport-type-random" value="random">use random local port</option>
120 <option value="fixed">bind to local port</option>
122 <input type="text" id="node-input-outport" style="width: 70px;" placeholder="port">
124 <div class="form-row">
125 <label> </label>
126 <input type="checkbox" id="node-input-base64" style="display: inline-block; width: auto; vertical-align: top;">
127 <label for="node-input-base64" style="width: 70%;">Decode Base64 encoded payload ?</label>
129 <div class="form-row">
130 <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
131 <input type="text" id="node-input-name" placeholder="Name">
133 <div class="form-tips">Tip: leave address and port blank if you want to set using <b>msg.ip</b> and <b>msg.port</b>.</div>
135 $("#node-input-multicast").change(function() {
136 var id = $("#node-input-multicast option:selected").val();
137 if (id !== "multi") {
138 $(".node-input-iface").hide();
139 $("#node-input-addr-label").html('<i class="fa fa-list"></i> Address');
140 $("#node-input-addr")[0].placeholder = 'destination ip';
143 $(".node-input-iface").show();
144 $("#node-input-addr-label").html('<i class="fa fa-list"></i> Group');
145 $("#node-input-addr")[0].placeholder = '225.0.18.83';
147 if (id === "broad") {
148 $("#node-input-addr")[0].placeholder = '255.255.255.255';
154 <script type="text/x-red" data-help-name="udp out">
155 <p>This node sends <b>msg.payload</b> to the designated udp host and port. Supports multicast.</p>
156 <p>You may also use <b>msg.ip</b> and <b>msg.port</b> to set the destination values.<br/><b>Note</b>: the statically configured values have precedence.</p>
157 <p>If you select broadcast either set the address to the local broadcast ip address, or maybe try 255.255.255.255, which is the global broadcast address.</p>
158 <p>On some systems you may need to be root to use ports below 1024 and/or broadcast.</p>
161 <script type="text/javascript">
162 RED.nodes.registerType('udp out',{
171 base64: {value:false,required:true},
172 multicast: {value:"false"}
176 icon: "bridge-dash.png",
179 return this.name||"udp "+(this.addr+":"+this.port);
181 labelStyle: function() {
182 return this.name?"node_label_italic":"";
184 oneditprepare: function() {
185 var type = this.outport==""?"random":"fixed";
186 $("#node-input-outport-type option").filter(function() {
187 return $(this).val() == type;
188 }).attr('selected',true);
190 $("#node-input-outport-type").change(function() {
191 var type = $(this).children("option:selected").val();
192 if (type == "random") {
193 $("#node-input-outport").val("").hide();
195 $("#node-input-outport").show();
199 $("#node-input-outport-type").change();
201 $("#node-input-multicast").change(function() {
202 var type = $(this).children("option:selected").val();
203 if (type == "false") {
204 $("#node-input-outport-type-random").html("bind to random local port");
206 $("#node-input-outport-type-random").html("bind to target port");
209 $("#node-input-multicast").change();