I am not sure if this is a language problem, but I could try.
For a project in our company, we are trying to implement a data transfer protocol for large files of size 22 MB via UDP. We know that TCP is better suited for this, but the hardware design decided that it was UDP.
The logic we received is a client sending a 22 MB file through 1500 byte packets. Each package has a unique identifier in its header. The first batch of these packets ~ 15000 takes about a second to transmit, but we, of course, lose ~ 2000 packets due to the use of UDP.
Each batch of packets ends with a unique βfinal packetβ, telling us that the transfer from the client is complete, and we can start to request lost packets through their unique identifier. Due to restrictions, we are allowed to request 255 packets at the same time, so we need to send a lot of requests for resending. Due to the final packet, we do not need to use a socket timeout, which would have to be ~ 250 ms per request cycle, in order to be effective without leaving more packets to transmit, resulting in a lot of time being wasted.
Now for the actual problem:
While the first cycle of requesting 255 packets and receiving them takes 0.01 s, each of them takes 0.4 s. I traced the root of the problem to the recv_from function. I made sure that it receives the same number of packets for each cycle before ending in the "end-package", and although it even reaches the same number of bytes, it takes 40 times.
fn receive( socket: &UdpSocket, buf: &mut [u8;1600] ) -> Vec<Vec<u8>>{ let mut res: Vec<Vec<u8>> = vec![]; let mut x = Duration::seconds( 0 ); loop{
Sorry for the huge wall of text, this is just a lot of the background that comes with this problem; not even sure that I mentioned everything that is appropriate.
source share