问题原文
原帖链接 · iamnp · CC BY-SA 3.0
Can TCP packets arrive to receiver by pieces?
For example, if I send 20 bytes using TCP protocol, can I be 100% sure that I will receive exactly 20 bytes at once, not 10 bytes then another 10 bytes or so?
And the same question for UDP protocol.
I know that UDP is unreliable and packets can not arrive at all or arrive in different order, but what about a single packet? If it arrives, can I be sure that it is a complete packet, not a piece?
社区高分解答
原帖链接 · Jim Cote · CC BY-SA 3.0
Examples. Blocks of contiguous characters correspond to send() calls:
TCP:
Send: AA BBBB CCC DDDDDD E Recv: A ABB B BCC CDDD DDDE
All data sent is received in order, but not necessarily in the same chunks.
UDP:
Send: AA BBBB CCC DDDDDD E Recv: CCC AA E
Data is not necessarily in the same order, and not necessarily received at all, but messages are preserved in their entirety.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
