TCP Client Connection Pass/Fail

12 vues (au cours des 30 derniers jours)
Rob A
Rob A le 14 Déc 2020
Réponse apportée : Rob A le 14 Déc 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

Réponse acceptée

Rob A
Rob A le 14 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by