Can you use multiple TCP/IP links in parallel on one device?
6 views (last 30 days)
Show older comments
I have a script that uses a TCP/IP link between Matlab and a different program (HAWC2) on the same pc to run simulations, which work when running regular for loop. However, when I want to run multiple simulations at the same time in a parforloop the TCP/IP connections all initially connect, but soon after some of them disconnect. So I was wondering if it is possible to run multiple connections at once or if there is some sort of maximum. The are all using the same host, but different portnumbers as specified by the below code:
parfor (ipar_temp = 1:length(ipar_list), N_cores)
ipar = ipar_list(ipar_temp);
%############################################
%############### Run HAWC2 ##################
%############################################
% Each simulation has a specific TCPportnumber
TCPportnumber = M.LoadCases.(list_DLCs{ipar}).TCPportnumber;
command = ['HAWC2MB.exe ' './htc/' folderName '/' list_DLCs{ipar} '.htc &'];
system(command);
% TCP/IP connection using local host & individual TCP
% portnumbers
TcpIpConnected = 0;
for i = 1:100
if TcpIpConnected
break,
end
pause(.1);
try
TCPOBJ = tcpclient('127.0.0.1',TCPportnumber,'Timeout',7200,'ConnectTimeout',30);
TcpIpConnected = 1;
catch TryTcpIpConnect
TcpIpConnected = 0;
fprintf('.')
end
end
% Call other script where information between two models is exchanged
HAWC2.HAWC2_VANILLA(TCPOBJ, preProcOutputTable);
clear TCPOBJ
% kill all processes else cmd prompts will accumulate
system('c:\Windows\System32\taskkill.exe /f /im cmd.exe');
end
0 Comments
Answers (1)
Walter Roberson
on 27 May 2022
Do not kill the command prompt from within the worker, you are killing the ones created by the other workers.
You should consider using System.Diagnostics.Process to control the connections.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!