Tcp {active, true} problem

Jim Larson <>
Sat Aug 5 01:07:00 CEST 2000


In message <> Martin Logan writes:
>	I am writing a proxy server in erlang. I have run into a slight
>problem with gen_tcp. I am using {active, true} and receiving with
>
>receive
>	{tcp, Socket, Packet} -> 
>end
>
>If I send packets to this at a 500 milliseconds apart I receive all of the
>packets perfectly and the proxy works well. My problem arises when I send
>a number of packets quickly( < 500 ms). I receive them as one large ascii
>string. I was wondering, befor I write a parser of sorts, if there is some
>other way to deal with this problem. 

On most systems, the TCP machinery is free to split or join packets
behind-the-scenes, since it's only providing reliable byte stream
service.  Any record separation must be done explicitly.  You can
either switch to UDP transport (and accept the possibility of loss,
duplication, or reordering of data), or you can implement your own
record separation.

The {packet, PacketType} option allows the low-level driver to
perform packetization for you, so that your Erlang code only deals
with discrete packets.  There are a variety of packet types built-in
to suit your needs.  The 1, 2, 4-type options will add the record
separator for both sending and receiving data.  If you have no
particular ties to any of the other packet types, I'd recommend
one of those.

Jim



More information about the erlang-questions mailing list