简体   繁体   English

Boost ASIO-丢弃的UDP数据包,与UE4 udp接收器相比,损失很大

[英]Boost ASIO - dropped UDP packets, significant loss compared to UE4 udp reciever

I am trying to use a simple async UDP listener using this . 我试图使用一个简单的异步UDP侦听器使用this I also use UE4 UDP Socket (FUdpSocketBuilder) in a game engine project. 我还在游戏引擎项目中使用UE4 UDP套接字(FUdpSocketBuilder)。 I don't run these two UDP listeners simultaneously. 我不会同时运行这两个UDP侦听器。 I get a series of byte array from a fixed udp port from another application in following order start 36, middle 65488 x 6 and end 400 bytes. 我从另一个应用程序的固定udp端口获取一系列字节数组,其顺序为开始36,中间65488 x 6和结束400字节。 But the problem is I miss 4 x 65488 bytes and sometimes I get the trailing 400 bytes in the boost asio example C++ app. 但是问题是我错过了4 x 65488字节,有时我在boost asio示例C ++应用程序中得到了尾随的400字节。 I have tried increasing the received byte array size to a high number including 7-8 times what is declared below: 我尝试将接收到的字节数组大小增加到一个高数字,包括下面声明的7-8倍:

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

What can I do, please advice ? 我该怎么办,请指教? I have also asked this question on Github . 我也在Github上问过这个问题。

Print from Boost ASIO UDP: 从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 !

Print from UE4: 从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.

I was able to fix the UDP packets loss issue today. 我今天能够解决UDP数据包丢失的问题。 It is not a concurrency issue that can be solved by using a separate thread. 这不是可以通过使用单独的线程来解决的并发问题。 It is the issue of data speed intra-epoch not inter-epoch. 这是数据速度跨时代而不是跨时代的问题。 What I mean by that is, it is a data stream that dumps UDP packets on the port epoch(significant event) to epoch with some acquisition delay in between. 我的意思是,这是一个数据流,该数据流将UDP数据包在端口epoch(重要事件)上转储到epoch,之间存在一些获取延迟。 That is the window of opportunity to process anything, not within the epoch, but just after the epoch which is the 400 trailing bytes. 那是处理任何东西的机会之窗,不是在时期内,而是在时期之后(即400个尾随字节)。 I am using a single threaded program but I have Boost ASIO i/o object for asynchronous operations. 我使用的是单线程程序,但我具有用于异步操作的Boost ASIO I / O对象。 All I do now is a fast memory copy of every byte array received until I hit a modulo - N(epoch bytes total), then I process each packet from the accumulated array, then I am able to collect all the data without any packet loss! 我现在要做的就是接收到的每个字节数组的快速内存副本,直到我达到模数-N(总共为纪元字节),然后处理累积数组中的每个数据包,然后我就可以收集所有数据而不会丢失任何数据包! Thanks for all the help @SergeyA 感谢您的所有帮助@SergeyA
If you want to read more about why it is not advisable to use threads besides making application complicated here is the link : The Proactor Design Pattern: Concurrency Without Threads. 如果您想了解更多有关为什么除了使应用程序变得复杂之外不建议使用线程的原因,请访问以下链接 :Proactor设计模式:无线程并发。

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

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