[erlang-questions] Erlang get_tcp:recv data length

Alain O'Dea alain.odea@REDACTED
Fri Feb 25 21:14:39 CET 2011


Precisely right :)

On Fri, Feb 25, 2011 at 3:26 PM, info <info@REDACTED> wrote:

>  If I resume your propositions (I hope that I understood them ...):
>
> Remind: packet ::= {message delimiter}
>
>
> main()->
> ...
> loop(Socket,<<>>).
>
> loop(Socket,BinAcc)->
> inet:setotps(Socket,[{active,once}]),
> receive
> {tcp,Socket,Bin} ->
> accumulate(BinAcc,Bin),
>                 case searchin(BinAcc,Delimiter) of
> {found,Message,Rest} ->
>                            process(Message),
> loop(Socket,<<Rest/binary>>);
> {not_found,_,_} ->
>                            loop(Socket,<<BinAcc/binary,Bin/binary>>)
> end;
> {tcp_closed,Socket} ->
> ...
> end.
>
> - The solution will be:
> - independant of the type of delimiter;
> - independant of the size of a message;
> - independant of the number of messages.
> - No need to detect the end of a packet of messages.
> - Standard recbuf can be used.
>
> Note:
> - I could have in Bin several messages. Only the first one is extracted and
> processed !
> - The code is bad because messages can stay in BinAcc
>
>  *J-Ph. Constantin*
> ITS3 Genève
> www.its3.ch
>


More information about the erlang-questions mailing list