Set time for fopen in tcp/ip communication

2 views (last 30 days)
Good afternoon,
I have been working on a tcp/ip connection between Matlab and Labview, in which both programs will act as a server and as a client as the same time.
While writing the code of Matlab, I have encounter a difficulty which I do not seem to find a solution, I would like that the program opens the connection but not infinitely but that the fopen(...) waits for a response on a certain time defined by me and if does not find anything on that stablished time continues the following lines of the code.
Until know I have managed to create two variants which do not work of course, but maybe there is another way which I am not seeing. I have been looking for a way for a while now and run out of ideas.
Version 1
for e = 1:50
pause(1);
retry = retry + 1;
if retry > number_of_retries
fprintf(1, 'Too many retries\n');
fclose(Connection);
return;
end
fprintf(1, ['Try %d waiting for client to connect to this ' ...
'host on port : %d\n'], retry, output_port);
fopen(Connection);
disp('Connection OK');
break
end
The connection remains open inf.
version 2 for e= 1:50
if ((number_of_retries > 0) && (retry > number_of_retries))
fprintf(1, 'Too many retries\n');
fclose(Connection);
return;
pause(1);
retry = retry + 1;
end
if(retry>1)
fprintf(1, ['Try %d waiting for client to connect to this ' ...
'host on port : %d\n'], retry, output_port);
fopen(Connection);
disp('Connection OK');
end;
end
This version simply does not open the connection at all.
Seriously there must be a way to control how long the fopen stays well; open...
I hope to hear from you soon, and I deeply thank you in advance if you find me a solution.

Answers (0)

Community Treasure Hunt

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

Start Hunting!