UDP in/out broadcast issue

Hello,

I've found an issue while using UDP in/out with broadcasting.
The scenario:

  • udp in listening on port 57066
  • udp out sending a broadcast packet and binding to local port 57066

(the goal is to discover another device IP address, and this device will reply when receiving a specific packet on a specific port).

When the udp out tries to send the message, it throws an EACCES error. This is because the SO_BROADCAST flag is not set.
Looking at the code, I see that udp out will reuse the socket of udp in if it already exists. But this socket will not have the broadcast flag.

If I change the code in the UDPout function by updating the code below, it works:

 node.tout = setTimeout(function() {
            if (udpInputPortsInUse[p]) {
                sock = udpInputPortsInUse[p];
                
                // start of modification:
                if (node.multicast == "broad") {
                      sock.setBroadcast(true);
                      sock.setMulticastLoopback(false);
                 }
                 // end of modification
                node.log(RED._("udp.status.re-use",{outport:node.outport,host:node.addr,port:node.port}));
                if (node.iface) { node.status({text:n.iface+" : "+node.iface}); }
            }

What do you guys think? Is it bug that could be corrected, or am I missing something?

I'm seeing the same behavior. Have you submitted a pull request?

1 Like

not seen one - but happy to patch it anyway.
can see that it would help

1 Like

I have the same issue now one yar later, what do i do to get it fixed and what is the new release number, or how do i patch.

It was fixed at that time so has been in every release since then.

hmhm cant get it to work. i can listen for udp messages thats working , but cannot send, it is sending but dont think it gets oustide the container network. if i run it in host mode i cant get the ui, like the port is not mapped in host mode..

se boot up log looks fine
27 Apr 11:29:55 - [info] Node-RED version: v1.3.2

27 Apr 11:29:55 - [info] Node.js version: v12.22.1

27 Apr 11:29:55 - [info] Linux 5.10.25-linuxkit x64 LE

27 Apr 11:29:55 - [info] Loading palette nodes

27 Apr 11:29:57 - [info] Dashboard version 2.28.2 started at /ui

27 Apr 11:29:57 - [info] Settings file : /data/settings.js

27 Apr 11:29:57 - [info] Context store : 'default' [module=memory]

27 Apr 11:29:57 - [info] User directory : /data

27 Apr 11:29:57 - [info] Projects directory: /data/projects

27 Apr 11:29:57 - [info] Server now running at http://127.0.0.1:1880/

27 Apr 11:29:57 - [info] Active project : node-red-docker

27 Apr 11:29:57 - [info] Flows file : /data/projects/node-red-docker/docker-custom/flows.json

27 Apr 11:29:57 - [info] Starting flows

MongoDB URL: mongodb://172.17.0.1:27017/Neets

27 Apr 11:29:57 - [info] Started flows

27 Apr 11:29:57 - [info] [udp in:NeetsDiscovery] udp listener at 0.0.0.0:8000

27 Apr 11:29:57 - [info] [udp in:Key changes] udp listener at 0.0.0.0:8001

27 Apr 11:29:57 - [info] [udp out:broadcast] udp broadcast ready: 2800 -> localhost:8000

27 Apr 11:29:57 - [info] [udp out:Send from port 3000] udp ready: 3000 -> :

27 Apr 11:29:57 - [info] [udp out:Send from port 3001] udp ready: 3001 -> :slight_smile:

and you have exposed that udp port via docker ?

Yep
I Think i found out why, it's because i am on a mac where there is a layer in between.
so it is not broadcasting om my house network only listening.

can this be true.

Lars