TCP连接会丢包吗? [英] Will TCP connection lose packets?

查看:75
本文介绍了TCP连接会丢包吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说服务器 S 与客户端 C 建立了成功的 TCP 连接.

Say Server S have a successful TCP connection with Client C.

C 不断向 S 发送 256 字节长的数据包.

C is keep sending 256-byte-long packets to S.

有没有可能其中一个数据包只收到一部分,但连接没有中断(可以继续正确接收新数据包)?

Is it possible that one of packets only receive part of it, but the connection does not break (Can continue receive new packets correctly)?

我认为 TCP 协议本身会保证在连接时不会丢失任何字节.但好像不行?

I thought TCP protocol itself will guarantee not lose any bytes while connecting. But seems not?

附言我正在使用 Python 的 socketserver 库.

P.S. I'm using Python's socketserver library.

推荐答案

TCP 协议确实保证交付.因此(假设您的代码和 TCP 堆栈中没有错误),您描述的场景是不可能的.

The TCP protocol does guarantee delivery. Thus (assuming there are no bugs in your code and in the TCP stack), the scenario you describe is impossible.

请记住,TCP 是面向流的,而不是面向数据包的.这意味着您可能需要多次调用 recv() 来读取整个 256 字节的数据包.

Do bear in mind that TCP is stream- rather than packet-oriented. This means that you may need to call recv() multiple times to read the entire 256-byte packet.

这篇关于TCP连接会丢包吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆