gpt4 book ai didi

sockets - 网络 : does it need to care TCP segments reassembly?

转载 作者:可可西里 更新时间:2023-11-01 02:41:14 28 4
gpt4 key购买 nike

我有一个关于 TCP 段重组的问题。我了解到数据包可以分为多个段(这与 MSS 有关)。

即)消息流(假设):

  1. 客户端发送一个从应用层传来的数据包
  2. 在客户端的TCP层,数据包分为3段。
  3. 传递给客户 IP 层的段。
  4. 服务器的 IP 层接收数据段。
  5. 在服务器端的TCP层,它接收3个数据包并将其重组为一个数据包。
  6. 服务器的应用层收到一个数据包。

我的理解是 TCP 层是分割的段重新组合的地方。如果我错了,请纠正我。

这是我真正想澄清的事情。

当使用 Netty 时,服务器端的“messageReceived()”方法只被调用一次还是 3 次?如果 TCP 层是重新组合分割段的地方,则“messageReceived()”方法只被调用一次,对吗?

那么,真的有必要使用“ReplayingDecoder”之类的东西来保证服务器接收的字节数吗?

非常感谢您的帮助。


附加问题:

如果服务器因为其中一个丢失或其他原因无法重新组装这些段,那么 TCP 层会将不完整的数据包传递给应用层?

最佳答案

the packet could be divided into multiple segments

上下颠倒,或错误的术语。 TCP 发送分段,这些分段被分成数据包,并且可能在途中进一步拆分为子数据包。

My understanding is that the TCP layer is where divided segments get reassembled.

数据包重组发生在 IP 层,而不是应用程序(或 TCP 层)。段重组发生在 TCP 层。

"messageReceived()" method gets called only one or 3 times?

它被调用从 1 到 N 的任意次数,其中 N 是字节流的长度。发送方发送和接收方接收之间不能保证 1::1 对应。

If the server fails to reassemble the segments because one of them is lost or something, then the TCP layer pass the incomplete packet to the application layer?

绝对不是。 TCP 根本不将数据包传递给应用层。它传递一个完整的、正确排序的字节流,或者什么都不传递。

Wondering if i should handle the segment reassembly by myself

您不会,也不能自己处理任何事情。 TCP 向应用程序提供字节流,而不是段或数据包。

关于sockets - 网络 : does it need to care TCP segments reassembly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14834602/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com