'recbuf' and the size of received data

Scott Lystig Fritchie fritchie@REDACTED
Sun Jun 24 09:19:46 CEST 2001

>>>>> "wb" == Willem Broekema <willem@REDACTED> writes:

wb> I have a problem receiving tcp packets with data larger than 1024
wb> bytes.

If you attempt to read N bytes from a TCP socket, you'll get at most N
bytes, but all other bets are off.  If the sender is transmitting in M
byte chunks, you may get M bytes when attempting to read N bytes
(assuming M < N), but you may not.  If you need message boundaries,
you need to use a different protocol (e.g. UDP) or you need to embed
those boundaries into the protocol you're using over TCP.

So, in your case, if recbuf is 2K, and you're gettings reads of 1K,
you'll just have to do another read and then concatenate the results.
There's no guarantee that your second read will be exactly 1K, either:
it might be 1.5K, which means you'll have to "carry over" 0.5K into
the next message you read.

Scott Lystig Fritchie
Professional Governing: Is It Faked?

More information about the erlang-questions mailing list