UDP packet loss receive

I am using Matlab to receive and process UDP packages sent from a microcontroller via Ethernet. This works without problems - but if I send a high amount of data, at a certain point UDP packages get lost in an random-looking way.
I assumed, that the InputBufferSize was too small, but increasing it had no effect. Also flushing the input buffer before the occurrence did not fix the problem. (The buffer is never full, checked with BytesAvailable).
Closing and re-opening the UDP connection fixes the problem, but causes a high delay and loss of data during the connection is closed.
I saved the packages to a text-file and compared them to the Wireshark packets. In Wireshark no packet loss happens.
%How I open the connection:
u=udp('192.168.0.100', 55055,'LocalPort', 55056,'DatagramTerminateMode','on', 'InputBufferSize',500000);
fopen(u);
flushinput(u);
u.Timeout = 1;
%How I read packages:
while(1)
[udp_package,count,msg] = fread(u);
fprintf(fileID,'%s\n',udp_package);
end

4 Comments

Is there a router or switch between the devices, or is the microcontroller connected directly by ethernet cable to a port on the computer?
directly connected!
I have the same problem. Only the sequence fopen(UDPobject) - fread(UDPobject) - fclose(UDPobject) for every read operation gives me a contiguous sequence of data without packet loss, but is slow. Have tried 'flushinput', changing 'inputBufferSize' and also reducing the data-rate from the source. All without success.
I also have the same problem. I have the same code working on a Windows 7 machine but when the setup was upgraded to Windows 10 this stopped working. I have tried disabling firewalls, changing network adapter priorities and increasing the specificity of my UDP port. None of this has worked:
udpport("datagram","LocalHost",'X.X.X.X',"LocalPort", X, "EnablePortSharing", true);

Sign in to comment.

Answers (1)

Matthias Kern
Matthias Kern on 24 Aug 2018

0 votes

I can confirm the issue. I want to read 5000 packages but after ~3500 I loose packages. The input buffer size is set to 5000*packageSize

Tags

Asked:

on 23 Nov 2015

Commented:

on 15 Mar 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!