什么时候在应用程序层对TCP网络数据包进行分段? [英] When will a TCP network packet be fragmented at the application layer?

查看:233
本文介绍了什么时候在应用程序层对TCP网络数据包进行分段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

何时在应用程序层对TCP数据包进行分段?从应用程序发送TCP数据包时,应用程序层的接收者是否会收到两个或更多数据包中的数据包?如果是这样,什么条件导致数据包被分割.看来直到达到以太网(在网络层)的1500个字节的限制,数据包才不会被分段.但是,该碎片对应用程序层的接收者是透明的,因为网络层将在将数据包发送到下一层之前重新组装碎片,对吗?

When will a TCP packet be fragmented at the application layer? When a TCP packet is sent from an application, will the recipient at the application layer ever receive the packet in two or more packets? If so, what conditions cause the packet to be divided. It seems like a packet won't be fragmented until it reaches the Ethernet (at the network layer) limit of 1500 bytes. But, that fragmentation will be transparent to the recipient at the application layer since the network layer will reassemble the fragments before sending the packet up to the next layer, right?

推荐答案

当它遇到MTU小于数据包大小的网络设备时,它将被拆分.大多数以太网设备为1500,但它通常会更小,例如1492(如果该以太网由于附加的路由信息​​而通过PPPoE(DSL)传输),如果添加第二层(如Windows Internet连接共享)则更低.而且拨号通常是576!

It will be split when it hits a network device with a lower MTU than the packet's size. Most ethernet devices are 1500, but it can often be smaller, like 1492 if that ethernet is going over PPPoE (DSL) because of the extra routing information, even lower if a second layer is added like Windows Internet Connection Sharing. And dialup is normally 576!

通常,尽管您应该记住 TCP不是分组协议.它使用最低级别的数据包通过IP进行传输,但是就任何TCP堆栈的接口而言,它是一种流协议,不需要为您发送或接收的物理数据包提供1:1关系. (例如,大多数堆栈将保留消息,直到特定时间段到期为止,或者有足够的消息来最大化给定MTU的IP数据包的大小)

In general though you should remember that TCP is not a packet protocol. It uses packets at the lowest level to transmit over IP, but as far as the interface for any TCP stack is concerned, it is a stream protocol and has no requirement to provide you with a 1:1 relationship to the physical packets sent or received (for example most stacks will hold messages until a certain period of time has expired, or there are enough messages to maximize the size of the IP packet for the given MTU)

作为一个示例,如果您发送了两个数据包"(两次调用send函数),则接收程序可能仅接收1个数据包"(接收方TCP堆栈可能将它们组合在一起).如果您要隐含基于TCP的消息类型协议,则应在每个消息的开头(或其他一些头/页脚机制)添加标头,以便接收方可以将TCP流拆分回单独的消息,无论是在发送一条消息时分为两个部分接收,或者以块的形式接收到几则消息.

As an example if you sent two "packets" (call your send function twice), the receiving program might only receive 1 "packet" (the receiving TCP stack might combine them together). If you are implimenting a message type protocol over TCP, you should include a header at the beginning of each message (or some other header/footer mechansim) so that the receiving side can split the TCP stream back into individual messages, either when a message is received in two parts, or when several messages are received as a chunk.

这篇关于什么时候在应用程序层对TCP网络数据包进行分段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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