[erlang-questions] [erlang-programming] Re: Source specific multicast

Anastasia spasennyi4ert@REDACTED
Fri Jul 25 19:31:03 CEST 2014


-module(udp_bin_ssm). 
-compile([export_all]). 

start([Source,Group,Port]) -> 
    {ok,SourceAddress} = inet:parse_address(Source), 
    {ok,GroupAddress} = inet:parse_address(Group),
    LocalIp = ip_to_binary({0,0,0,0}),
    GroupIp = ip_to_binary(GroupAddress),
    SourceIp = ip_to_binary(SourceAddress),
    Bin = << GroupIp/binary,LocalIp/binary,SourceIp/binary >>,
    {ok,Socket} = gen_udp:open(erlang:list_to_integer(Port), 
        [ 
            inet, 
            binary, 
            {active,true}, 
            {reuseaddr,true},
            {multicast_ttl, 30},
        {raw, 0, 39, Bin}
        ]), 
    io:format("Socket ~p:~n", [Socket]), 
    Pid = spawn(fun() -> loop(Socket) end), 
    io:format("Pid :~p~n",[Pid]),             
    ok = gen_udp:controlling_process(Socket,Pid). 
 
ip_to_binary(Ip) ->
    list_to_binary(tuple_to_list(Ip)).

loop(Socket) -> 
    receive 
        {udp,_Socket,_SrcAddr,_Port,Bin} -> 
            io:format("Bin ~p:~n", [Bin]),           
            loop(Socket); 
        Msg -> 
            io:format("Msg ~p:~n", [Msg]) 
    end.

вторник, 15 июля 2014 г., 8:09:37 UTC+4 пользователь Anastasia написал:
>
> What should I change or add to the code in order to run the code with 
> source specific multicast?
>
> -module(udp_bin). 
> -compile([export_all]). 
>  
> start([Host,Port]) -> 
>     {ok,IpAddress} = inet:parse_address(Host), 
>     {ok,Socket} = gen_udp:open(erlang:list_to_integer(Port), 
>         [ 
>             inet, 
>             binary, 
>             {active,true}, 
>             {reuseaddr,true}, 
>             {add_membership,{IpAddress,{0,0,0,0}}} 
>         ]), 
>     io:format("Socket ~p:~n", [Socket]), 
>     Pid = spawn(fun() -> loop(Socket) end), 
>     io:format("Pid :~p~n",[Pid]),            %%15 
>     ok = gen_udp:controlling_process(Socket,Pid). 
>  
>  
> loop(Socket) -> 
>     receive 
>         {udp,_Socket,_SrcAddr,_Port,Bin} -> 
>             io:format("Bin ~p:~n", [Bin]),           %%25 
>             loop(Socket); 
>         Msg -> 
>             io:format("Msg ~p:~n", [Msg]) 
>     end.
>

-- 
You received this message because you are subscribed to the Google Groups "Erlang Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erlang-programming+unsubscribe@REDACTED
To post to this group, send email to erlang-programming@REDACTED
Visit this group at http://groups.google.com/group/erlang-programming.
For more options, visit https://groups.google.com/d/optout.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140725/9dc713f7/attachment.htm>


More information about the erlang-questions mailing list