Failed to establish a TCP connection between two computers on MATLAB

1 view (last 30 days)
Fan Yang
Fan Yang on 1 Nov 2021
I am try to establish a TCP connection between two computers using tcpserver and tcpclient so that the client send a number 0 every second and the server reveives and shows the input.
Below is the code on the client's side:
tcp_c = tcpclient('',60000,'Timeout',30);% creat a client with port 60000
% tcp_c.OutputBufferSize = 1000;% set buffer size for output
fopen(tcp_c); %open the client
data = 0;
while true
% if fread(tcp_c,1,'double') == 1; % read the input data: each number takes 8 bytes
% t = timer('BusyMode','queue','ExecutionMode','fixedDelay','Period',1,'TimerFcn',"disp('q')");
% end
% data = fgetl(tcp_c)
% data = fscanf(tcp_c,'string',len)
%time = (toc-1)*1000;
% fclose(tcp_c);
Below is the code on the server's side:
tcp_s = tcpserver('',60000,'Timeout',30);% creat a server with port 60000
% tcp_s.InputBufferSize = 1000;% set buffer size for input
fopen(tcp_s); %open the server
while true
d = fread(tcp_s,1,'double')
% fclose(tcp_a);
Everytime I run, matlab return an error say"
"The requested address is not valid in its context"
and refered to the documentation below for troubleshooting:
I followed all the step in the document, but it still did not work.
When I change the ip on the server to '0,0,0,0' so it listens to all that talk to port 60000, it returned a different errer saying the first input of fopen must be a file identifier or a file name.
Ive ran out of idea on how to fix it or even when went wrong. Please Help!!!!!

Answers (0)

Community Treasure Hunt

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

Start Hunting!