Skip to content

Instantly share code, notes, and snippets.

@spscream
Created September 7, 2012 07:04
Show Gist options
  • Select an option

  • Save spscream/3664006 to your computer and use it in GitHub Desktop.

Select an option

Save spscream/3664006 to your computer and use it in GitHub Desktop.
loop(ListenSocket, SENDURL) ->
inet:setopts(ListenSocket, [{active, once}]),
{_, _, Host, Port, _Path, _Query} = http_uri2:parse(SENDURL),
receive
{udp, ListenSocket, _Host, _Port, Bin} ->
gen_udp:send(ListenSocket, Host, Port, decode(Bin)),
loop(ListenSocket, SENDURL)
end.
decode(Bin) -> decode(Bin, []).
decode(<<>>, Acc) -> lists:reverse(Acc);
%decode(<<16#47, Packet:187/binary, Rest/binary>>, Acc) ->
% decode(Rest, [Acc|Packet]);
decode(<<Char, Rest/binary>>, Acc) ->
decode(Rest, [Char|Acc]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment