Socket module (NIF) UDP example?

pablo platt pablo.platt@REDACTED
Mon Oct 28 18:31:06 CET 2019


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
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

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:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list