[erlang-questions] Beginner: Windows UDP multicast receive

Scott Gregory <>
Tue Jun 24 19:09:04 CEST 2008


Hello

(I also posted this to the "Advanced Erlang/OTP" forum - apologies if either
is the wrong place).

Absolute Erlang newbie here, trying to do a UDP multicast receive on Windows
as a useful/interesting test case for my purposes.

Version is: Erlang (BEAM) emulator version 5.6.3 [smp:2] [async-threads:0]

Below is my code - What I am trying to do is listen on "address" 224.0.66.66
"port" 6666.
My computer's regular IP address is 192.168.6.49 on our internal network.

The code "runs" ok, but never seems to receive anything, I always get the
"huh" output, and I know from other handlers that there are all sorts of
packets flying by on this multicast address.

Help?!

Scott

Code:

-module(listen).
-export([init/0, loop/1]).

loop(Socket) ->
        io:format("in-loop~n"),
        receive
                {udp, Socket, Host, Port, Bin} ->
                        io:format("host",Host),
                        io:format("Port: ", Port),
                        io:format("BinSize: ", size(Bin)),
                        loop(Socket);
                {udp, _ } ->
                        io:format("got one")
        after 2000 ->
                io:format("huh?~n")
        end,
        gen_udp:close(Socket).


init() ->
        {ok, Socket} = gen_udp:open(6666, [binary,
                                        {reuseaddr,true},
                                        {multicast_loop,true},
                                        {ip,{192,168,6,49}},
 
{add_membership,{{224,0,66,66},{192,168,6,49}}}]),
        loop(Socket).




More information about the erlang-questions mailing list