[erlang-questions] Broadcast UDP message
Cameron Kerr
ckerr@REDACTED
Thu Jun 11 01:36:41 CEST 2009
From a system perspective, this will depend on the OS, as the
specifics for how 255.255.255.255 is routed changes on different
operating systems.
If you are on Linux, I think you need to have a route entry that will
match (typically your default route) Note that it only use this to
determine which interface to send to (it will not use the gateway).
Given your error of ENETUNREACH, this is almost certainly what will be
happening.
Some other systems will choose the "primary interface", which is the
first BROADCAST, UP interface.
Also note that 255.255.255.255 should only really be used for
bootstrap purposes when you don't have a better IP configuration;
typically only protocols such as DHCP and routing protocols should use
it; user applications should almost always use the subnet-directed
broadcast address.
On 11/06/2009, at 2:53 AM, Lucas Robsahm wrote:
> Hi!
>
> I'm trying to send a broadcast message to 255.255.255.255 but I can't
> get it to work.
> My IP-Address is 192.168.1.1 and it's ok to send UDP message to
> 192.168.1.255 but I need to send it to 255.255.255.255.
>
> {ok, Socket} = gen_udp:open(0, [binary, {broadcast, true}]),
> ok = gen_udp:send(Socket, {255, 255, 255, 255}, 68, Message).
>
> The result of this is badmatch, {error, enetunreach}.
>
> What's wrong?
> How can i broadcast UDP messages?
>
> //Lucas
--
Cameron Kerr <ckerr@REDACTED>
Teaching Fellow, Computer Science, University of Otago
More information about the erlang-questions
mailing list