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 comentarios

Walter Roberson
Walter Roberson el 23 de Nov. de 2015
Is there a router or switch between the devices, or is the microcontroller connected directly by ethernet cable to a port on the computer?
Josef Stein
Josef Stein el 23 de Nov. de 2015
directly connected!
Luigi
Luigi el 20 de Feb. de 2018
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.
Gideon Bergbaum
Gideon Bergbaum el 15 de Mzo. de 2021
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);

Iniciar sesión para comentar.

Respuestas (1)

Matthias Kern
Matthias Kern el 24 de Ag. de 2018

0 votos

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

Categorías

Etiquetas

Preguntada:

el 23 de Nov. de 2015

Comentada:

el 15 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by