Receiving data in TCP

See Transmission Control Protocol:

TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer.

A “stream” means that there is no message boundary from the receiver’s point of view. You could get one 1000 byte message or one thousand 1 byte messages depending on what’s underneath and how often you call read/select.

Edit: Let me clarify from the application’s point of view. No, TCP will not guarantee that the single read would give you all of the 1000 bytes (or 1MB or 1GB) packet the sender may have sent. Thus, a protocol above the TCP usually contains fixed length header with the total content length in it. For example you could always send 1 byte that indicates the total length of the content in bytes, which would support up to 255 bytes.

Leave a Comment