Why fread does not work in my UDP connection?
显示 更早的评论
I have 2 computer connected via an ethernet cable, and I want to set up a UDP connection between them. On the computer associated with IP 192.168.0.1 I have the script
ipA = '192.168.0.1';
portA =9090;
ipB = '192.168.0.3';
portB =9091;
udpA = udp(ipB, portB, 'LocalPort',portA,'LocalHost',ipA)
fopen(udpA)
fwrite(udpA, 1:10)
fclose(udpA)
while on the computer associated with IP '192.168.0.3' I have the script
ipA='192.168.0.1';
portA=9090;
ipB='192.168.0.3';
portB = 9091
udpB = udp(ipA,portA,'LocalPort',portB,'LocalHost',ipB)
fopen(udpB)
a=fread(udpB,10);
fclose(udpB)
I put both script in the editor, ready to be run just playing F5. So I run the latter and the former, but the fread function does not give any results in a, which at the end is empty. Instead, Matlab returns a warning "Warning: Returning data as an array since it is not the same size as requested. You may want to set the DataTermination Mode to 'off'".
However, I tried that, and I also tried not to launch the script but simply commands an the two terminals. But nothing seems to work, and in true I have never been able to set up a UDP connection.
Any ideas? What I am doing wrong?
I'm sorry to ask another question on UDP but really I have read tons of forum and still it isn't working, I am running out of ideas.
EDIT: I want to add that inserting the command line udpA/udpB before the final fclose, I get from udpA
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 10
but from udpB
Read/Write State
TransferStatus: idle
BytesAvailable: 0
ValuesReceived: 0
ValuesSent: 0
Please note the line with no values received.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Import and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!