Первое задание

Aug 22, 2014 14:20

-переписать код с чистого Erlang'а на OTP/Erlang

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

start([Sourse, 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 = <>,
{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.

посмотрим что вынесла из прочтения книг.
Previous post Next post
Up