udp丢包和恢复

发布于 2024-11-02 05:43:32 字数 251 浏览 0 评论 0原文

我正在开发基于 udp/tcp 的 P2P 文件和实时视频流应用程序。该应用程序将使用 C++ 为 Linux 和 Windows 平台开发。

我们使用ICE(TCP/UDP打洞)来实现P2P。 虽然 TCP 确保数据包丢失,但对于 UDP,我需要一种合适的方法来确保数据包必须传递到另一个对等点。

  1. 我想知道执行此操作的算法或技术。
  2. 有没有免费的第三方工具/库可以做。

任何链接和建议将不胜感激?

I am working on both udp/tcp based P2P for file and real time video streaming application.the application will be developed for both Linux and windows platform using c++.

We are using ICE(TCP/UDP hole punching) to implement the P2P.
while TCP ensure the packet loss but for UDP I need a decent approach to make sure packet must be delivered to the other peer.

  1. I wanted to know the algorithm or technique to do this.
  2. Is there any free thord party tool/libraries to do.

Any link and suggestion will be appreciated?

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

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

发布评论

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

评论(3

深海不蓝 2024-11-09 05:43:32

您需要解决 4 个主要问题:

  1. 数据切片 - UDP 数据报不能包含无限量的信息。因此,您(经常)需要将信息分割成多个数据报,并在另一端重新连接拼图。对于给定的“切片”,您需要唯一的标识符和拼图块编号。
  2. 从未到达 - UDP 数据报有时可能会在网络上丢失。如果目标对等点没有收到预期的数据报,则应该有一种机制让他再次请求。另一种方法是在接收时发送确认。
  3. 重播 - 有时,您可能会两次收到相同的 UDP 数据报(由于复杂的原因)。目标对等点应该检测到这一点。
  4. 乱序 - 发送顺序并不总是接收顺序。目标对等点需要处理这种情况。

您可以实现一个名为切片窗口的协议。我认为您不会为此找到第 3 方库(尽管有人可能会在这里证明我是错的),因为以上所有内容通常都是由 TCP 本身实现的。

You need to cover for 4 main issues:

  1. Data slicing - UDP datagrams cannot contain an infinite amount of information. Therefore, you will (often) need to slice your information into multiple datagrams and reconnect the puzzle pieces at the other end. For a given 'slicing', you need unique identifier and puzzle piece number.
  2. Never Reached - UDP datagrams can sometime get lost on the net. If a target peer does not receive an expected datagram, there should be a mechanism letting him request it again. Another method is to send a confirmation upon reception.
  3. Replay - Sometimes, you may receive the same UDP datagram twice (for complex reasons). The target peer should detect this.
  4. Out-of-order - The order of sending is not always the order of receiving. A target peer needs to handle this situation.

There is a protocol called slicing window which you could implement. I don't think you'll find a 3rd party library for this (though someone may prove me wrong here), because all the above is typically implemented by TCP itself.

岁月如刀 2024-11-09 05:43:32

您可能会发现此问题的答案很有帮助:您使用什么什么时候需要可靠的UDP?

You might find the answers to this question helpful: What do you use when you need reliable UDP?

悲念泪 2024-11-09 05:43:32

一种简单的方法是为每个数据包设置一个监视线程——

public void run() {
    int transmissions = 0;
    do {
        sendPacket();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {}
    } while (!acknowledged() && ++transmissions < MAX_TRANSMISSIONS);
}

如果性能很重要,则可以使用单个线程来监视消息队列。

A simple approach would be to have a monitoring thread for each packet --

public void run() {
    int transmissions = 0;
    do {
        sendPacket();
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {}
    } while (!acknowledged() && ++transmissions < MAX_TRANSMISSIONS);
}

If performance is important, a single thread could be used to monitor a queue of messages.

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