warning in udp using fscanf

조회 수: 1 (최근 30일)
Rashi Mehrotra
Rashi Mehrotra 2021년 8월 11일
편집: Walter Roberson 2021년 8월 24일
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