better socket connection error handling

This commit is contained in:
2026-09-06 09:31:13 -05:00
parent b6630d844c
commit 93db005db1
+2 -3
View File
@@ -28,15 +28,14 @@ def main():
# open TCP connection to server # open TCP connection to server
with socket() as sock: with socket() as sock:
sock.settimeout(args.socket_timeout or 30)
try: try:
sock.connect((RCON_ADDRESS, RCON_PORT)) 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} Connection to server failed. {RST}")
print(f"{GRY} Please check the server hostname and port, then try again. {RST}") print(f"{GRY} Please check the server hostname and port, then try again. {RST}")
exit(1) exit(1)
sock.settimeout(args.socket_timeout or 30)
# login attempts # login attempts
login_success = login(sock, RCON_PASSWORD) login_success = login(sock, RCON_PASSWORD)
while (not login_success): while (not login_success):