[erlang-questions] Erlang get_tcp:recv data length

Roberto Ostinelli <>
Tue Feb 22 18:50:14 CET 2011


2011/2/22 Alexander Kuleshov <>

> Thank you for reply.
>
> >And by the way, number 1418 is very likely your MTU value.
>
> Then how can i recieve more than 1 packet?
>

..looping?

http://www.erlang.org/doc/man/gen_tcp.html

server() ->
    {ok, LSock} = gen_tcp:listen(5678, [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.


More information about the erlang-questions mailing list