UDP 是否允许重新打包? [英] Does UDP allow repacketization?

查看:10
本文介绍了UDP 是否允许重新打包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道对于 TCP,您可以启用例如 Nagle 算法.但是,您可以为 UDP 提供类似的东西吗?

I know that for TCP you can have for example Nagle's Algorithm enabled. However, can you have something similar for UDP?

实用问题(假设 UDP 套接字):

如果我在短时间内调用 send() 两次,每次 send() 调用中有 1 个字节的数据.传输层是否可能决定只发送 1 个 UPD 数据包,其中 1 字节 + 1 字节 = 2 字节 数据?

If I call send() two times in a short period of time with 1 byte of data in each send() call. Is it possible that the transport layer decides to send only 1 UPD packet with the 1 byte + 1 byte = 2 bytes of data?

提前致谢!

推荐答案

不符合 RFC (RFC 768).在 IP 设施本身之上,UDP 实际上只提供了额外的基于端口的路由和一点点额外的损坏或路由错误检测.

Not according to the RFC (RFC 768). Above IP facilities themselves, UDP really only provides, as extras, port-based routing and a little bit of extra detection for corruption or misrouting.

这意味着无法组合数据报.事实上,由于它是面向事务的,我会说将两个事务合并为一个可能是一个的想法,因为这会使这些事务保持不同.

That means there's no facility to combine datagrams. In fact, since it's meant to be transaction oriented, I would say that combining two transactions into one may well be a bad idea in terms of keeping these transaction disparate.

否则,您将需要在 UDP 之上的一个层来计算如何从数据报中提取这些事务.目前,这不是必需的,因为数据报事务.

Otherwise, you would need a layer above UDP which could figure out how to extract these transactions from a datagram. At the moment, that's not necessary since the datagram is the transaction.

作为对这种争用的添加支持(当然不是确定的),请参阅 UDP 维基百科页面:

As added support (though not, of course, definitive) for this contention, see the UDP wikipedia page:

数据报——数据包是单独发送的,只有在它们到达时才检查完整性.数据包有明确的边界,在接收时遵守,这意味着接收方套接字上的读取操作将产生一整条消息,就像它最初发送的那样.

Datagrams – Packets are sent individually and are checked for integrity only if they arrive. Packets have definite boundaries which are honored upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.

但是,对它的最佳支持来自它的一位客户.UDP 是专门为 TFTP(除其他外)设计的,如果您无法区分事务,该协议就会崩溃.

However, the best support for it comes from one of its clients. UDP was specially engineered for TFTP (among other things) and that protocol breaks down if you cannot distinguish a transaction.

具体来说,TFTP 事务类型之一是 data 事务,它由操作码、块号和最多 512 字节的数据组成.如果在开始时没有长度指示或在结束时没有标记值,则 没有 方法来确定下一个事务将从哪里开始,除非事务和数据报之间存在一对一的映射.

Specifically, one of the TFTP transaction types is the data transaction which consists of an opcode, block number and up to 512 bytes of data. Without a length indication at the start or a sentinel value at the end, there is no way to work out where the next transaction would start unless there is a one-to-one mapping between transaction and datagram.

顺便说一句,其他四种 TFTP 事务类型具有固定长度或字符串结尾标记值,但 data 事务是此处的决定者.

As an aside, the other four TFTP transaction types have either a fixed length or end-of-string sentinel values but the data transaction is the decider here.

这篇关于UDP 是否允许重新打包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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