client 3 次自动退出
This commit is contained in:
parent
11f0f89727
commit
60beb1f363
@ -264,6 +264,9 @@ def listen_for_requests(sock):
|
|||||||
|
|
||||||
def connect_to_b_device(b_host, b_port):
|
def connect_to_b_device(b_host, b_port):
|
||||||
"""Connect to device B and handle requests"""
|
"""Connect to device B and handle requests"""
|
||||||
|
failure_count = 0
|
||||||
|
max_failures = 3
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
@ -278,6 +281,10 @@ def connect_to_b_device(b_host, b_port):
|
|||||||
if not response or b"PROXY_CONNECTED" not in response:
|
if not response or b"PROXY_CONNECTED" not in response:
|
||||||
log_error("System", "Failed to receive connection confirmation")
|
log_error("System", "Failed to receive connection confirmation")
|
||||||
sock.close()
|
sock.close()
|
||||||
|
failure_count += 1
|
||||||
|
if failure_count >= max_failures:
|
||||||
|
log_error("System", "Maximum connection attempts reached (%d), exiting..." % max_failures)
|
||||||
|
sys.exit(1)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -285,6 +292,7 @@ def connect_to_b_device(b_host, b_port):
|
|||||||
sock.sendall(b"READY\r\n")
|
sock.sendall(b"READY\r\n")
|
||||||
log_info("System", "Successfully connected to device B: %s:%d" % (b_host, b_port))
|
log_info("System", "Successfully connected to device B: %s:%d" % (b_host, b_port))
|
||||||
|
|
||||||
|
failure_count = 0
|
||||||
listen_for_requests(sock)
|
listen_for_requests(sock)
|
||||||
|
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
@ -292,9 +300,17 @@ def connect_to_b_device(b_host, b_port):
|
|||||||
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
|
log_info("System", "Device B not ready (%s:%d), retrying in 3 seconds..." % (b_host, b_port))
|
||||||
else:
|
else:
|
||||||
log_error("System", "Connection error: %s" % str(e))
|
log_error("System", "Connection error: %s" % str(e))
|
||||||
|
failure_count += 1
|
||||||
|
if failure_count >= max_failures:
|
||||||
|
log_error("System", "Maximum connection attempts reached (%d), exiting..." % max_failures)
|
||||||
|
sys.exit(1)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_error("System", "Unexpected error: %s" % str(e))
|
log_error("System", "Unexpected error: %s" % str(e))
|
||||||
|
failure_count += 1
|
||||||
|
if failure_count >= max_failures:
|
||||||
|
log_error("System", "Maximum connection attempts reached (%d), exiting..." % max_failures)
|
||||||
|
sys.exit(1)
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user