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

发布于 2024-10-18 17:22:27 字数 587 浏览 1 评论 0原文

我一直致力于为我自己的游戏开发副业项目编写自己的网络引擎。这需要具有不可靠、可靠和有序可靠消息的选项。然而,我还没有能够确定可靠和有序的可靠协议所需的所有机制。

UDP 上的可靠层需要哪些机制?感谢您提供更多详细信息。

到目前为止,我认为这些是要求:

  • 使用序列号确认收到的消息。
  • 在重传时间到期后重新发送未确认的消息。
  • 跟踪每个目的地的往返时间,以便计算适当的重传时间。
  • 识别并删除重复的数据包。
  • 处理循环溢出的序列号。

这影响了我的架构,使其具有带有序列和时间戳的可靠消息头、回显接收到的序列和时间戳的确认消息、基于地址跟踪适当重传时间的系统,以及 a) 接收消息并将其排队以供用户接收的线程,b) 确认可靠的消息,以及 c) 使用过期的重传定时器来重传未确认的消息。

注意: 可靠的 UDP 与 TCP 不同。即使有序可靠的UDP也与TCP不一样。我并不是私下里不知道我真的想要 TCP。另外,在有人玩语义游戏之前,是的……可靠的 UDP 是一个“矛盾修辞法”。这是 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? 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.

NOTE:
Reliable UDP is not the same as TCP. Even ordered reliable UDP is not the same as TCP. I am not secretly unaware that I really want TCP. Also, before someone plays the semantics games, yes... reliable UDP is an "oxymoron". This is a layer over UDP that makes for reliable delivery.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

人生戏 2024-10-25 17:22:27

您可能想查看此问题的答案:当您需要可靠的 UDP 时,您会使用什么?

我会将“流量控制”添加到您的列表中。您希望能够根据您获得的往返时间来控制在特定链接上发送的数据量,否则您将淹没该链接并丢弃数据报。

You might like to take a look at the answers to this question: What do you use when you need reliable 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.

你的往事 2024-10-25 17:22:27

请注意,根据总体协议,可能可以省去重传计时器。例如,请参阅Quake 3 网络协议

在 Q3 中,只需发送可靠数据包,直到看到确认为止。

Note that depending on the overall protocol, it might be possible to dispense with retransmission timers. See, for example, the Quake 3 network protocol.

In Q3 reliable packets are simply sent until an ack is seen.

紫罗兰の梦幻 2024-10-25 17:22:27

为什么要尝试重新发明 TCP?它提供了您最初所说的所有功能,并且已被证明运行良好。

编辑 - 由于您的评论表明您有最初未说明的附加要求,因此您应该考虑使用多个套接字的混合模型是否比尝试在单个应用程序层协议中满足所有这些标准更好。

实际上,您真正需要的是 SCTP

SCTP 支持:

  1. 基于消息(而不是字节流)
  2. 通过单个 netsock 套接字传输多个流
  3. 有序或无序数据包接收

... SCTP 中消息排序是可选的;接收应用程序可以选择按照消息接收的顺序而不是发送的顺序来处理消息

Why are you trying to re-invent 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 supports:

  1. message based (rather than byte stream) transmissions
  2. multiple streams over a single netsock socket
  3. ordered or unordered receipt of packets

... message ordering is optional in SCTP; a receiving application may choose to process messages in the order they are received instead of the order they were sent

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文