From 93db005db12466f2d5035b14237b79e394080d79 Mon Sep 17 00:00:00 2001 From: Evan Scherrer Date: Sun, 6 Sep 2026 09:31:13 -0500 Subject: [PATCH] better socket connection error handling --- src/main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 31755f3..98030f2 100644 --- a/src/main.py +++ b/src/main.py @@ -28,15 +28,14 @@ def main(): # open TCP connection to server with socket() as sock: + sock.settimeout(args.socket_timeout or 30) try: sock.connect((RCON_ADDRESS, RCON_PORT)) - except: + except OSError: # OSError is the parent of a few different errors we want to gracefully catch here print(f"{GRY} Connection to server failed. {RST}") print(f"{GRY} Please check the server hostname and port, then try again. {RST}") exit(1) - sock.settimeout(args.socket_timeout or 30) - # login attempts login_success = login(sock, RCON_PASSWORD) while (not login_success):