sockets - limitation of the reception buffer -
i established connection client way:
gen_tcp:listen(1234,[binary,{packet,0},{reuseaddr,true},{active,false},{recbuf,2048}]).
this code performs message processing:
loop(socket)-> inet:setops(socket,[{active,once}], receive {tcp,socket,data}-> handle(data), loop(socket); {pid,cmd}-> gen_tcp:send(socket,cmd), loop(socket); {tcp_close,socket}-> % ... end.
my os windows. when size of message 1024 bytes, lose bytes in data
. server sends ack + fin client.
i believe erlang limited 1024 bytes, therefore defined recbuf
.
where problem is: erlang, windows, hardware?
thanks.
you may setting receive buffer far small. erlang isn't limited 1024 byte buffer. can check doing following in shell:
{ok, s} = gen_tcp:connect("www.google.com", 80, [{active,false}]), o = inet:getopts(s, [recbuf]), gen_tcp:close(s), o.
on mac os x default receive buffer size of 512kb.
with {packet, 0}
parsing, you'll receive tcp data in whatever chunks network stack chooses send in, have message boundary parsing , buffering yourself. have reliable way check message boundaries in wire protocol? if so, receive tcp data , append buffer variable until have complete message. call handle on complete message , remove complete message buffer before continuing.
we more if gave information on client , protocol in use.
Comments
Post a Comment