TCP Client Connection Pass/Fail

11 Ansichten (letzte 30 Tage)
Rob A
Rob A am 14 Dez. 2020
Beantwortet: Rob A am 14 Dez. 2020
I am looking for a pass/fail status the the initial TCP connection.
% If the TCP connection is successful then variable 't' is created.
% If it's not successful, then the variable 't' is not created, BUT the
% code execution is also aborted so the if statement below is never executed.
t = tcpclient('192.168.1.15', 52801);
if exist('t','var')
disp('TCP Connection setup');
else
disp('TCP Connection not setup');
end
When the TCP connection is unsuccessful, an error message is generated in the console, and the code execution is aborted. This is the error message in the console:
Error using Untitled (line 2)
Cannot create a communication link with the remote server. Please check the input arguments(ADDRESS and PORT) and make sure the server is running.
Additional Information: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Is there another way to check that status of a tcp connection with the Instrument Control Toolbox? (i.e. A ping command that doesn't require the "MATLAB Compiler SDK").
Thank you!
Rob

Akzeptierte Antwort

Rob A
Rob A am 14 Dez. 2020
MATALB support was able to quickly give me a solution which was to utilize the "try/catch" statement.
I modified my code to test it out and it worked out well:
try
t = tcpclient('192.168.1.15', 52801);
catch
end
if exist('t','var')
disp('TCP Connection setup');
else
disp('TCP Connection not setup');
end

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by