Skip to content

Commit 11699c1

Browse files
committed
Reset connections if one fails
This way we avoid getting into a situation where things might restart while attempting to connect to one of the sockets.
1 parent 64e7010 commit 11699c1

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

resources/external_control.urscript

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ def connect_socket_with_retry(host, port, name, max_attempts=5, dt=0.2):
850850
attempt = 0
851851
while attempt < max_attempts:
852852
if socket_open(host, port, name):
853+
textmsg("Successfully connected to ", name)
853854
return True
854855
end
855856
sleep(dt)
@@ -864,21 +865,19 @@ end
864865

865866
# Attempt to establish the three required socket connections, if at least one socket is still disconnected,
866867
# a popup is shown and the loop continues until all three flags are True.
867-
868868
traj_flag = False
869869
com_flag = False
870870
rev_flag = False
871-
872871
while not (traj_flag and com_flag and rev_flag):
873872
if not traj_flag:
874873
traj_flag = connect_socket_with_retry("{{SERVER_IP_REPLACE}}", {{TRAJECTORY_SERVER_PORT_REPLACE}}, "trajectory_socket")
875874
end
876875

877-
if traj_flag and not com_flag:
876+
if not com_flag:
878877
com_flag = connect_socket_with_retry("{{SERVER_IP_REPLACE}}", {{SCRIPT_COMMAND_SERVER_PORT_REPLACE}}, "script_command_socket")
879878
end
880879

881-
if traj_flag and com_flag and not rev_flag:
880+
if not rev_flag:
882881
rev_flag = connect_socket_with_retry("{{SERVER_IP_REPLACE}}", {{SERVER_PORT_REPLACE}}, "reverse_socket")
883882
end
884883

@@ -892,6 +891,21 @@ while not (traj_flag and com_flag and rev_flag):
892891
str_cat("<br/>Reverse socket ({{SERVER_PORT_REPLACE}}) connected: ", rev_flag),
893892
"<br/><br/>Please check that the external control end at {{SERVER_IP_REPLACE}} is running correctly. Press 'Continue' to retry."))),
894893
title="Error connecting to remote", blocking=True, error=True)
894+
895+
if traj_flag:
896+
socket_close("trajectory_socket")
897+
traj_flag = False
898+
end
899+
900+
if com_flag:
901+
socket_close("script_command_socket")
902+
com_flag = False
903+
end
904+
905+
if rev_flag:
906+
socket_close("reverse_socket")
907+
rev_flag = False
908+
end
895909
end
896910
end
897911

0 commit comments

Comments
 (0)