warning in udp using fscanf

1 次查看(过去 30 天)
Rashi Mehrotra
Rashi Mehrotra 2021-8-11
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.

回答(1 个)

Walter Roberson
Walter Roberson 2021-8-11
  • 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 个评论
Rashi Mehrotra
Rashi Mehrotra 2021-8-24
I have matlab 2018 version. How can I do in that?
Walter Roberson
Walter Roberson 2021-8-24
编辑:Walter Roberson 2021-8-24
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.)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by