【问题标题】:Boost ASIO - dropped UDP packets, significant loss compared to UE4 udp recieverBoost ASIO - 丢弃的 UDP 数据包,与 UE4 udp 接收器相比损失显着
【发布时间】:2018-11-30 10:46:24
【问题描述】:

我正在尝试使用this 使用简单的异步 UDP 侦听器。我还在游戏引擎项目中使用 UE4 UDP Socket (FUdpSocketBuilder)。我不会同时运行这两个 UDP 侦听器。我从另一个应用程序的固定 udp 端口​​获取一系列字节数组,顺序如下:开始 36、中间 65488 x 6 和结束 400 字节。但问题是我错过了 4 x 65488 字节,有时我会在 boost asio 示例 C++ 应用程序中得到尾随的 400 字节。我尝试将接收到的字节数组大小增加到一个很大的数字,包括下面声明的 7-8 倍:

 constexpr int udp_buffer_size = 65536;  // Max limit of each packet size
 boost::array<char, udp_buffer_size> recv_buffer_;

我该怎么办,请指教?我也在Github上问过这个问题。

从 Boost ASIO UDP 打印:

I just recieved 36 bytes of data !
I just recieved 65488 bytes of data !
I just recieved 65488 bytes of data !
I just recieved 36 bytes of data !
I just recieved 65488 bytes of data !
I just recieved 65488 bytes of data !

从 UE4 打印:

[2018.11.28 - 17.18.29:724][829]SomeProjectLog:  Warning : 2297. Recieved Bytes from UDP 36.
[2018.11.28 - 17.18.29:724][829]SomeProjectLog : Warning : 2298. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:724][829]SomeProjectLog : Warning : 2299. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:725][829]SomeProjectLog : Warning : 2300. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:725][829]SomeProjectLog : Warning : 2301. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:725][829]SomeProjectLog : Warning : 2302. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:725][829]SomeProjectLog : Warning : 2303. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:726][829]SomeProjectLog : Warning : 2304. Recieved Bytes from UDP 400.
[2018.11.28 - 17.18.29:726][829]SomeProjectLog : Warning : 2305. Recieved Bytes from UDP 36.
[2018.11.28 - 17.18.29:726][829]SomeProjectLog : Warning : 2306. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:726][829]SomeProjectLog : Warning : 2307. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:726][829]SomeProjectLog : Warning : 2308. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:727][829]SomeProjectLog : Warning : 2309. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:727][829]SomeProjectLog : Warning : 2310. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:727][829]SomeProjectLog : Warning : 2311. Recieved Bytes from UDP 65488.
[2018.11.28 - 17.18.29:727][829]SomeProjectLog : Warning : 2312. Recieved Bytes from UDP 400.

【问题讨论】:

  • 一个 65488 字节的 UDP 数据包?虽然技术上可行,但您为什么要这样做?
  • 它来自另一个应用程序,我无法控制,我只是从固定端口读取。但我想了解为什么 65k 字节是个坏主意?
  • 因为 UDP 没有保证交付。任何超过 MTU 大小(可能是 1500 字节)的数据包都将被分解为几个低级数据报,以便在接收端进行组装。如果接收方至少丢失了其中一个数据包,则整个序列都将被丢弃。在你的情况下,你最终得到 44 个数据包。
  • 点了,但我对发送的内容没有任何控制权,它是外部数据源应用程序,但无论如何应该看两件事,真的没有真正的网络通信发生,因为外部应用程序托管并在本地计算机上发送。其次是 UE4 udp 接收器准确地获取所有字节,所以为什么不应该 ASIO UDP !
  • 我没有得到它在本地机器上的事实。最可能的原因是性能。您的 ASIO 服务器将减慢处理数据的速度,因此会丢弃数据包。

标签: c++ boost udp packet-loss


【解决方案1】:

我今天能够解决 UDP 数据包丢失问题。这不是一个可以通过使用单独的线程来解决的并发问题。这是时代内而不是时代间的数据速度问题。我的意思是,它是一个数据流,它将端口时代(重要事件)上的 UDP 数据包转储到时代,其间有一些采集延迟。这是处理任何事情的机会之窗,不是在纪元内,而是在纪元之后,即 400 个尾随字节。我使用的是单线程程序,但我有用于异步操作的 Boost ASIO i/o 对象。我现在所做的只是对收到的每个字节数组进行快速内存副本,直到我达到模数 - N(总纪元字节总数),然后我处理累积数组中的每个数据包,然后我能够收集所有数据而不会丢失任何数据包!感谢@SergeyA 的所有帮助
如果您想详细了解为什么除了使应用程序复杂之外不建议使用线程,请参阅link:Proactor 设计模式:没有线程的并发。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-07
    • 1970-01-01
    • 2020-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多