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

余超 yuchao1@REDACTED
Thu Mar 31 09:15:55 CEST 2011


于 2011/3/31 15:04, Joe Armstrong 写道:
>
>
> On Tue, Mar 29, 2011 at 5:45 AM, zhangbo <bo.zhang86@REDACTED 
> <mailto:bo.zhang86@REDACTED>> 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
>     erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>     http://erlang.org/mailman/listinfo/erlang-questions
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
Joe:
nice!
thanks

-- 
Best Regards
余超  YuChao  UC:yuchao86@REDACTED
产品研发部 公共服务平台
电话:(8610)62676661
手机:13466539920 MSN:yuchao86@REDACTED
地址:北京市海淀区北四环西路58号理想国际大厦15层22-2
___________________________________________
http://www.sina.com.cn     You're the one
    新浪.北京                 一切由你开始

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110331/50ee764f/attachment.htm>


More information about the erlang-questions mailing list