Why fread does not work in my UDP connection?

2 views (last 30 days)
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.

Accepted Answer

Nick
Nick on 5 Mar 2014
Disable Windows Firewall. No comment.
  1 Comment
Samuel Gray
Samuel Gray on 18 Mar 2021
um, to be more complete, before you try using the ip stack in matlab, make sure that it works from the windows command line. You should be able to use ping to verify the connections and netstat to verify the service ports when they connect.
I can't say that I've gotten either tcp or udp to work in matlab between two different machines but at least I've gotten TCP to work between matlab and a linux box.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!