Re: Re: [erlang-questions] Erlang get_tcp:recv data length
info
info@REDACTED
Fri Feb 25 19:56:50 CET 2011
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