TCP Client Connection Pass/Fail

조회 수: 12 (최근 30일)
Rob A
Rob A 2020년 12월 14일
답변: Rob A 2020년 12월 14일
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

채택된 답변

Rob A
Rob A 2020년 12월 14일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by