Skip to content

Instantly share code, notes, and snippets.

@bmizerany
Created August 1, 2008 22:41
Show Gist options
  • Save bmizerany/3700 to your computer and use it in GitHub Desktop.
Save bmizerany/3700 to your computer and use it in GitHub Desktop.
-module (eh).
-compile([export_all]).
server() ->
{ok, LSock} = gen_tcp:listen(8000, [binary, {packet, 0},
{active, false}]),
{ok, Sock} = gen_tcp:accept(LSock),
{ok, Bin} = do_recv(Sock, []),
ok = gen_tcp:close(Sock),
Bin.
do_recv(Sock, Bs) ->
case gen_tcp:recv(Sock, 0) of
{ok, B} ->
do_recv(Sock, [Bs, B]);
{error, closed} ->
{ok, list_to_binary(Bs)}
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment