Created
August 1, 2008 22:41
-
-
Save bmizerany/3700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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