-module(udp_bin_ssm). <br>-compile([export_all]). <br><br>start([Source,Group,Port]) -> <br>    {ok,SourceAddress} = inet:parse_address(Source), <br>    {ok,GroupAddress} = inet:parse_address(Group),<br>    LocalIp = ip_to_binary({0,0,0,0}),<br>    GroupIp = ip_to_binary(GroupAddress),<br>    SourceIp = ip_to_binary(SourceAddress),<br>    Bin = << GroupIp/binary,LocalIp/binary,SourceIp/binary >>,<br>    {ok,Socket} = gen_udp:open(erlang:list_to_integer(Port), <br>        [ <br>            inet, <br>            binary, <br>            {active,true}, <br>            {reuseaddr,true},<br>            {multicast_ttl, 30},<br>        {raw, 0, 39, Bin}<br>        ]), <br>    io:format("Socket ~p:~n", [Socket]), <br>    Pid = spawn(fun() -> loop(Socket) end), <br>    io:format("Pid :~p~n",[Pid]),             <br>    ok = gen_udp:controlling_process(Socket,Pid). <br> <br>ip_to_binary(Ip) -><br>    list_to_binary(tuple_to_list(Ip)).<br><br>loop(Socket) -> <br>    receive <br>        {udp,_Socket,_SrcAddr,_Port,Bin} -> <br>            io:format("Bin ~p:~n", [Bin]),           <br>            loop(Socket); <br>        Msg -> <br>            io:format("Msg ~p:~n", [Msg]) <br>    end.<br><br>вторник, 15 июля 2014 г., 8:09:37 UTC+4 пользователь Anastasia написал:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir="ltr">What should I change or add to the code in order to run the code with source specific multicast?<br><br>-module(udp_bin).
<br>-compile([export_all]).
<br> <br>start([Host,Port]) ->
<br>    {ok,IpAddress} = inet:parse_address(Host),
<br>    {ok,Socket} = gen_udp:open(erlang:list_to_<wbr>integer(Port),
<br>        [
<br>            inet,
<br>            binary,
<br>            {active,true},
<br>            {reuseaddr,true},
<br>            {add_membership,{IpAddress,{0,<wbr>0,0,0}}}
<br>        ]),
<br>    io:format("Socket ~p:~n", [Socket]),
<br>    Pid = spawn(fun() -> loop(Socket) end),
<br>    io:format("Pid :~p~n",[Pid]),            %%15
<br>    ok = gen_udp:controlling_process(<wbr>Socket,Pid).
<br> <br> <br>loop(Socket) ->
<br>    receive
<br>        {udp,_Socket,_SrcAddr,_Port,<wbr>Bin} ->
<br>            io:format("Bin ~p:~n", [Bin]),           %%25
<br>            loop(Socket);
<br>        Msg ->
<br>            io:format("Msg ~p:~n", [Msg])
<br>    end.<br></div></blockquote>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups "Erlang Programming" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="mailto:erlang-programming+unsubscribe@googlegroups.com">erlang-programming+unsubscribe@googlegroups.com</a>.<br />
To post to this group, send email to <a href="mailto:erlang-programming@googlegroups.com">erlang-programming@googlegroups.com</a>.<br />
Visit this group at <a href="http://groups.google.com/group/erlang-programming">http://groups.google.com/group/erlang-programming</a>.<br />
For more options, visit <a href="https://groups.google.com/d/optout">https://groups.google.com/d/optout</a>.<br />