:gen_udp getting {:error, :eacces} error on message broadcast

Hi,

I am trying to broadcast a UDP packet from my Raspberry Pi and receive it from another node in the same network. I am following this example Sending and Receiving UDP

I can open the port successfully but when I am trying to send the udp message to the broadcast address of the network (192.168.1.255) I am getting the {:error, :eacces} error. It works fine when I broadcast to 127.0.0.1. I know it is related to permission denied but I don’t understand which permission.

Thanks, Tas

Sending to a broadcast address will fail unless the socket uses the SO_BROADCAST option. For :gen_udp, the option is spelled like:

{:ok, socket} = :gen_udp.open(8680, broadcast: true)
6 Likes

Thank you. It was well hidden in the documentation.