[erlang-questions] Re: about a tcp question in erlang

Pablo Platt <>
Thu Mar 31 18:02:42 CEST 2011


The {packet,2}, (or {packet,4} is great in cases that it can be used.
For example, in the mongodb wire protocol the size header is int32 little-endian which include the int32 (packet size+4Bytes).
http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol#MongoWireProtocol-MessagesTypesandFormats


Is there a chance this feature be extended to support little/big endianess and offset? It was previously requested here:

http://erlang.2086793.n4.nabble.com/packet-PacketType-for-little-signed-packets-td2244372.html



________________________________
From: Joe Armstrong <>
To: zhangbo <>
Cc: 
Sent: Thursday, March 31, 2011 9:04 AM
Subject: [erlang-questions] Re: about a tcp question in erlang





On Tue, Mar 29, 2011 at 5:45 AM, zhangbo <> wrote:

Hi,
>       Code:
>       {ok, Listen} = gen_tcp:listen(80, [{packet,0},
>                                       binary,
>                                       {active, true}])
>
>       Loop:
>               receive
>                       {tcp, S, Bin} ->
>                               ...
>
>I want to know, when a client send a message("helloworld") to server, then send another message("helloworld2"). How many messages will the server receive? (I guess 2.)  If the client send very fast, or the message is big enough, how the situation again?
>
>When receive {tcp, S, Bin}, Bin stands for a message or maybe just a fragment of message? If the client send "hello, server", Bin maybe "hello, server", but If the message is very big, what will Bin be? and how many times will the loop receive?
>

because you have said {packet,0} then data might become fragmented. The options {packet,2}, (or {packet,4} mean "send a 2(4) byte length header at the start of the data". If the client and server
both open a socket with {packet,4} then any fragmentation will be taken care of by the tcp driver. In this
case any packet fragments will be recombined by the driver and only completed messages delivered to
the application.

/Joe
 

 

>
>
>_______________________________________________
>erlang-questions mailing list
>
>http://erlang.org/mailman/listinfo/erlang-questions
>

_______________________________________________
erlang-questions mailing list

http://erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110331/d544eef0/attachment.html>


More information about the erlang-questions mailing list