-record(state, {
socket
}).
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
init([]) ->
%% open socket
{ok, Socket} = gen_udp:open(6970, [binary, {active, true}]),
{ok, #state{socket = Socket}}.
handle_call(_Request, _From, State) ->
{reply, ok, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info({udp, _Socket, _Addr, _Port, Data}, State) ->
io:format("Data: ~p~n", [Data]),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.
......
When UDP packets arrive at the opened port, if the socket is in an active mode the packets are delivered as messages to the controlling process:
{udp, Socket, IP, InPortNo, Packet}
А вообще есть отличная документация http://www.erlang.org/doc/ http://www.erlang.org/doc/man/gen_udp.html и т.д.