Im writing a Server-Client program with the socket module. At some point the client connects to the server with 'sock.connect((IP, PORT))' but if there is no server listening for a connection the client throws an exception. My question is how do I catch this exception to try again? Maybe with a 5 second pause in between until the server is up to catch the connection. I have tried:
while True:
try:
sock.connect((IP, PORT))
except ConnectionRefusedError:
time.sleep(5)
but another exception is thrown 'OSError: [Errno 22] Invalid argument'. Should I catch this exception as well? Is it even possible to catch this exception without ending the program?