How to send and receive UDP broadcast messages

Hi, there. I'm trying to send and listen for UDP broadcast messages using the UDP nodes. This post started as a question, but as I was writing it I managed to get it to work. I'm still posting this as I don't think it works as intended.

It turns out there were two separate issues I was dealing with.

First issue: When I left the destination IP empty on the sender the node threw an error: "udp: ip address not set". My expectation was that it would figure out the correct broadcast address from the network interfaces' IP/mask. The correct address for my network is 172.27.255.255.

The second issue is that it does not seem to be able to listen and send UDP packets at the same time even if the bind address is set to "random local port".

Depending on which node you add first, only sending or receiving works. The receiver is set to listen to messages on the broadcast port. The sender is set to send broadcast messages to the broadcast port and bind to a random local port. It does bind to a random port (I can see it from another device listening), but the receiver node does not receive any messages. OR the receiver receives messages and the sender throws an EACCES error.

The workaround is to set the sender to bind to a specific local port other than the broadcast port.

I'm currently running this on a Raspbery Pi zero w and a 3 b+.

1 Like