warning in udp using fscanf
Show older comments
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('172.16.52.22', 'Localport',15005,'InputBuffersize',10000);
whos u
u.EnablePortSharing = 'on'
u.Timeout=1;
fopen(u)
while (true)
display('hello')
y=fscanf(u,'%s');
end
I am not receiving any data in y it is gives an empty string, please help.
Answers (1)
Walter Roberson
on 11 Aug 2021
0 votes
- 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
5 Comments
Rashi Mehrotra
on 11 Aug 2021
Rashi Mehrotra
on 11 Aug 2021
Walter Roberson
on 11 Aug 2021
The destination IP is 226.1.1.1 . That is an address in the range reserved for Multicast groups.
You cannot join a multicast group using the code you used.
- To join a multicast group, you have to bind your local IP address for the connection to be the IP address of the multicast group. However, the udp() interface did not permit binding to a particular IP address.
- After binding to the correct interface, you need to inform the kernel that you want to join the multicast group. MATLAB does not provide any method of doing that.
The udp() interface is being replaced and is not documented as of R2020b. The newer interface is https://www.mathworks.com/help/instrument/udpport.html which requires you to explicitly indicate datagram.
The new interface has explicit multicast support using additional calls... but on Windows only; see https://www.mathworks.com/help/instrument/udpport.configuremulticast.html
Rashi Mehrotra
on 24 Aug 2021
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.)
Categories
Find more on Job and Task Creation 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!