简体   繁体   English

UDP上可靠层需要哪些机制?

[英]What are the required mechanisms for a reliable layer over UDP?

I've been working on writing my own networking engine for my own game development side projects. 我一直在为自己的游戏开发方面的项目编写自己的网络引擎。 This requires the options of having unreliable, reliable, and ordered reliable messages. 这需要具有不可靠,可靠和有序可靠消息的选项。 I have not, however, been able to identify all of the mechanisms necessary for reliable and ordered reliable protocols. 但是,我无法确定可靠和有序可靠协议所必需的所有机制。

What are the required mechanisms for a reliable layer over UDP? UDP上可靠层需要哪些机制? Additional details are appreciated. 附加的细节表示赞赏。

So far, I gather that these are requirements: 到目前为止,我认为这些是要求:

  • Acknowledge received messages with a sequence number. 确认收到的带有序列号的消息。
  • Resend unacknowledged messages after a retransmission time expires. 重传时间到期后,重新发送未确认的消息。
  • Track round trip times for each destination in order to calculate an appropriate retransmission time. 跟踪每个目的地的往返时间,以便计算适当的重传时间。
  • Identify and remove duplicate packets. 识别并删除重复的数据包。
  • Handle overflowing sequence numbers looping around. 处理溢出的序列号。

This has influenced my architecture to have reliable message headers with sequences and timestamps, acknowledge messages that echo a received sequence and timestamp, a system for tracking appropriate retransmission times based on address, and a thread that a) receives messages and queues them for user receipt, b) acknowledges reliable messages, and c) retransmits unacknowledged messages with expired retransmission timers. 这影响了我的体系结构,使其具有带有序列和时间戳的可靠消息头,确认消息以回显接收到的序列和时间戳,基于地址跟踪适当的重传时间的系统以及一个线程,该线程a)接收消息并将其排队以供用户接收,b)确认可靠消息,并且c)使用过期的重传计时器重传未确认的消息。

NOTE: Reliable UDP is not the same as TCP. 注意:可靠的UDP与TCP不同。 Even ordered reliable UDP is not the same as TCP. 甚至订购的可靠UDP也与TCP不同。 I am not secretly unaware that I really want TCP. 我并不是暗中没有意识到我真的想要TCP。 Also, before someone plays the semantics games, yes... reliable UDP is an "oxymoron". 另外,在有人玩语义游戏之前,是的……可靠的UDP是“矛盾的”。 This is a layer over UDP that makes for reliable delivery. 这是UDP上的一层,可确保可靠的传送。

You might like to take a look at the answers to this question: What do you use when you need reliable UDP? 您可能想看看以下问题的答案: 当您需要可靠的UDP时使用什么?

I'd add 'flow control' to your list. 我会在您的列表中添加“流控制”。 You want to be able to control the amount of data you're sending on a particular link depending on the round trip time's you're getting or you'll flood the link and just be throwing datagrams away. 您希望能够根据所获得的往返时间来控制在特定链接上发送的数据量,否则您将淹没该链接而只是丢掉数据报。

Note that depending on the overall protocol, it might be possible to dispense with retransmission timers. 请注意,根据整个协议,有可能省去重传计时器。 See, for example, the Quake 3 network protocol . 参见例如Quake 3网络协议

In Q3 reliable packets are simply sent until an ack is seen. 在第3季度中,仅发送可靠的数据包,直到看到确认为止。

Why are you trying to re-invent TCP? 您为什么要重新发明TCP? It provides all of the features you originally stated, and has been show to work well. 它提供了您最初声明的所有功能,并且已经证明可以正常工作。

EDIT - Since your comments show that you have additional requirements not originally stated, you should consider whether a hybrid model using multiple sockets would be better than trying to fulfill all of those criteria in a single application-layer protocol. 编辑-由于您的评论表明您还有其他最初未说明的要求,因此,应考虑使用多个套接字的混合模型是否比尝试在单个应用程序层协议中满足所有这些条件更好。

Actually it seems that what you really need is SCTP . 实际上,您似乎真正需要的是SCTP

SCTP supports: SCTP支持:

  1. message based (rather than byte stream) transmissions 基于消息(而不是字节流)的传输
  2. multiple streams over a single netsock socket 一个Netsock套接字上有多个流
  3. ordered or unordered receipt of packets 有序或无序的数据包接收

... message ordering is optional in SCTP; ...消息排序在SCTP中是可选的; a receiving application may choose to process messages in the order they are received instead of the order they were sent 接收应用程序可以选择按照接收消息的顺序而不是发送消息的顺序处理消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM