<div dir="ltr">
<div>Hi,</div><div><br></div><div>I have a gen_udp server in production and I want to test the performance of the new socket NIF.</div><div><br></div><div>How can I receive a message asynchronously similar to {active, once} in gen_udp?</div><div>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?<br></div><div><br></div><div>With gen_udp I open the socket with random port:<br></div><div>{ok, Socket} = gen_udp:open(0, [binary, {active, once}, {recbuf, 4096}])</div><div><br></div><div>Send data to a remote socket:<br></div><div>gen_udp:send(Socket, Addr, Port, Data),</div><div><br></div><div>Receive data with {active, one}<br></div><div>handle_info({udp, Socket, Addr, Port, Data}, State) -><br> % process data<br> inet:setopts(Socket, [{active, once}]),<br> {noreply, State}.</div><div><br></div><div>Close the socket:<br></div><div>
gen_udp:close(Socket), <br></div><div><br></div>
</div>