TCP网络数据包什么时候会在应用层分片? [英] When will a TCP network packet be fragmented at the application layer?

查看:25
本文介绍了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)

举个例子,如果你发送了两个数据包"(调用你的发送函数两次),接收程序可能只收到 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天全站免登陆