warning in udp using fscanf

4 views (last 30 days)
Rashi Mehrotra
Rashi Mehrotra on 11 Aug 2021
Edited: Walter Roberson on 24 Aug 2021
I received an warning Unsuccessful read: A time out occurred befor termination was reached, udp unable to read any data.
my code is as follows:
u = udp('', 'Localport',15005,'InputBuffersize',10000);
whos u
u.EnablePortSharing = 'on'
while (true)
I am not receiving any data in y it is gives an empty string, please help.

Answers (1)

Walter Roberson
Walter Roberson on 11 Aug 2021
  • the other end might not be sending any data at all
  • the other end might be sending to a different port
  • the other end might be waiting for you to send something before sending anything to you
  • the other end might not have started sending anything yet
  • you are configured for terminator mode, not for datagram mode. The other end might not be sending terminators. This is a common problem: you need to be consistent about datagram vs terminator vs fixed record size
Walter Roberson
Walter Roberson on 24 Aug 2021
Edited: Walter Roberson on 24 Aug 2021
In R2018a or R2018b, you will need to call a C or C++ dll or a mex function, that has been coded to talk to the operating system to create join a multicast group and act as a "broker" for you, reading from the udp socket and returning the data to MATLAB as just plain data (with the existence of the udp multicast socket hidden.)
It is not as simple as just requesting to open a UDP socket. Multicasting requires kernel support (because it has to deliver the packet to all of the processes on the same host that subscribe to the same group), and joining a multicast group requires kernel support (the kernel is responsible for all the overhead packets needed to negotiate with the multicast publisher where it is that the kernel is going to get sent the packets from.) The multicast protocol does not permit any host to "subscribe only": any host that subscribes to the multicast becomes responsible for helping distribute packets to other networks, and for helping maintain the Spanning Tree of distribution of packets.
I would suggest to you that it would be a lot simpler to upgrade to R2020b or later and use the new multicast-listen operation (assuming you are on Windows; if you are on a different OS then unfortunately that library call is not supported.)

Sign in to comment.


Find more on Application Deployment in Help Center and File Exchange


Community Treasure Hunt

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

Start Hunting!