0

I am trying to use a simple async UDP listener using this. I also use UE4 UDP Socket (FUdpSocketBuilder) in a game engine project. I don't run these two UDP listeners simultaneously. 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. 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. I have tried increasing the received byte array size to a high number including 7-8 times what is declared below:

 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.

Print from 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:

[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.
Syed Alam Abbas
  • 521
  • 6
  • 21
  • A UDP packet of 65488 bytes? While technically possible, why would you do this? – SergeyA Nov 28 '18 at 19:03
  • It is coming from another app, that I don't have control, I am just reading from a fixed port. But I would like to get educated as to why 65k bytes is bad idea ? – Syed Alam Abbas Nov 28 '18 at 19:04
  • Because UDP has no guaranteed delivery. Any packet which exceeds MTU size (likely 1500 bytes) is going to be broken up into several low-level datagrams to be assembled on the receiving side. If the receiving side misses at least one of those packets, the whole sequence is dropped. In your case, you end up with 44 packets. – SergeyA Nov 28 '18 at 19:09
  • Point taken, but I dont have any control of what is being sent, it is external data source app, but in any case there are two things that should be looked at, there is really no true network communication happening, since the external app is hosted and sending on local machine. Second is that UE4 udp reciever get all the bytes exactly so why shouldn't ASIO UDP ! – Syed Alam Abbas Nov 28 '18 at 19:13
  • I didn't get the fact that it is on the local machine. Than the most likely reason is performance. Your ASIO server is to slow processing data, so packets are dropped. – SergeyA Nov 28 '18 at 19:19
  • Are you saying that is an inherent flaw in ASIO or that I am slow in the processing of the bytes received since I am merely printing on cout, how slow can that be ? – Syed Alam Abbas Nov 28 '18 at 19:27
  • I have no idea where the slowness comes from. This is just one of the reasons why you might miss packets. – SergeyA Nov 28 '18 at 19:35
  • Could concurrency be an issue here, but I cant believe a single threaded I/O which is not doing much work would let some packets be skipped ? – Syed Alam Abbas Nov 29 '18 at 17:48

1 Answers1

0

I was able to fix the UDP packets loss issue today. 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. That is the window of opportunity to process anything, not within the epoch, but just after the epoch which is the 400 trailing bytes. I am using a single threaded program but I have Boost ASIO i/o object for asynchronous operations. 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! Thanks for all the help @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.

Syed Alam Abbas
  • 521
  • 6
  • 21