Socket module (NIF) UDP example?
pablo platt
pablo.platt@REDACTED
Mon Oct 28 18:31:06 CET 2019
Hi,
I have a gen_udp server in production and I want to test the performance of
the new socket NIF.
How can I receive a message asynchronously similar to {active, once} in
gen_udp?
Do I need to keep a queue of outgoing packets in case the send buffer is
full and resend them? Can I just increase the send buffer and ignore this
complexity?
With gen_udp I open the socket with random port:
{ok, Socket} = gen_udp:open(0, [binary, {active, once}, {recbuf, 4096}])
Send data to a remote socket:
gen_udp:send(Socket, Addr, Port, Data),
Receive data with {active, one}
handle_info({udp, Socket, Addr, Port, Data}, State) ->
% process data
inet:setopts(Socket, [{active, once}]),
{noreply, State}.
Close the socket:
gen_udp:close(Socket),
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20191028/c671d45a/attachment.htm>
More information about the erlang-questions
mailing list