
11 May
2011
11 May
'11
3:51 p.m.
On 5/11/2011 10:11 AM, Slav wrote:
TCP contains info about message length - it is duplication to prefix all messages with it's length.
No, it really doesn't. All you get is a stream of bytes, reliably delivered, in sequence. So if you write 3,732 bytes onto a socket, there is *NO WAY* for the reader to tell that you did that. The reader might get 1 read of 3732 bytes, or 3732 reads of 1 byte, or anything in between. The reader could even read *more* than 3732 bytes in one read, if you wrote more than once. If you think you're going to get repeatable, identical matching pairs of reads and writes out of just a TCP socket (that is, without imposing your own protocol on top of TCP), you are in for endless hours/days/months of frustration.