Joined December 2014
·

Drew

USA
·
·

My previous comment seems to be deleted.

Thank you for posting this, it is exactly the type of thing I was needing. Earlier it was crashing the erl VM every time I ran test_stuff(), but now it seems to be working, I have no idea why.

I also noticed what I think to be is a bug in the the:

handle_info(timeout, #state{ id=ID, sock=Sock } = State) ->
  TO = case gen_udp:recv(Sock, 4) of
    {error, _} -> 10;
    _Data ->
      catch ets:insert_new(?MODULE, {ID, 0}),
      catch ets:update_counter(?MODULE, ID, 1)
  end,
  {noreply, State, TO}.

code you are setting the timeout to the result of the ets:update_counter, probably not what you want, I changed it to:

handle_info(timeout, #state{ id=ID, sock=Sock } = State) ->
  TO = case gen_udp:recv(Sock, 4) of
    {error, _} -> 10;
    _Data ->
      catch ets:insert_new(?MODULE, {ID, 0}),
      catch ets:update_counter(?MODULE, ID, 1),
      10 % <--- TO = 10 not  TO = ets:update_counter(..)
  end,
  {noreply, State, TO}.

and the throughput of the server doubled.

Thanks again for this gem, there is a complete lack of use of UDP in the Erlang literature.

Achievements
1 Karma
0 Total ProTip Views