大网数据广告活动
服务器运维问答

Can TCP and UDP packets be split into pieces?

· 52CE 我爱测

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 fo…

问题原文

原帖链接 · 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2013-08-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。