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


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 ( I am getting the {:error, :eacces} error. It works fine when I broadcast to 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)

Thank you. It was well hidden in the documentation.