update UDP node to not bind output port if not required to do so.

Fix to Close #165
This commit is contained in:
Dave C-J 2014-02-20 20:59:05 +00:00
parent 46765d5737
commit 0bc4a3bbb1
2 changed files with 12 additions and 11 deletions

View File

@ -72,7 +72,6 @@
color:"Silver", color:"Silver",
defaults: { defaults: {
name: {value:""}, name: {value:""},
host: {value:""},
iface: {value:""}, iface: {value:""},
port: {value:"",required:true,validate:RED.validators.number()}, port: {value:"",required:true,validate:RED.validators.number()},
datatype: {value:"buffer",required:true}, datatype: {value:"buffer",required:true},

View File

@ -22,7 +22,6 @@ function UDPin(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.group = n.group; this.group = n.group;
this.port = n.port; this.port = n.port;
this.host = n.host || null;
this.datatype = n.datatype; this.datatype = n.datatype;
this.iface = n.iface || null; this.iface = n.iface || null;
this.multicast = n.multicast; this.multicast = n.multicast;
@ -64,7 +63,7 @@ function UDPin(n) {
catch (err) { console.log(err); } catch (err) { console.log(err); }
}); });
server.bind(node.port,node.host); server.bind(node.port);
} }
RED.nodes.registerType("udp in",UDPin); RED.nodes.registerType("udp in",UDPin);
@ -81,16 +80,19 @@ function UDPout(n) {
var node = this; var node = this;
var sock = dgram.createSocket('udp4'); // only use ipv4 for now var sock = dgram.createSocket('udp4'); // only use ipv4 for now
sock.bind(node.port); // have to bind before you can enable broadcast...
if (this.multicast != "false") { if (this.multicast != "false") {
sock.setBroadcast(true); // turn on broadcast sock.bind(node.port, function() { // have to bind before you can enable broadcast...
if (this.multicast == "multi") { sock.setBroadcast(true); // turn on broadcast
sock.setMulticastTTL(128); if (this.multicast == "multi") {
sock.addMembership(node.addr,node.iface); // Add to the multicast group sock.setMulticastTTL(128);
node.log('udp multicast ready : '+node.addr+":"+node.port); sock.addMembership(node.addr,node.iface); // Add to the multicast group
} node.log('udp multicast ready : '+node.addr+":"+node.port);
else node.log('udp broadcast ready : '+node.addr+":"+node.port); }
else node.log('udp broadcast ready : '+node.addr+":"+node.port);
});
} }
else node.log('udp ready : '+node.addr+":"+node.port); else node.log('udp ready : '+node.addr+":"+node.port);
node.on("input", function(msg) { node.on("input", function(msg) {