I want to write a code to achieve below
I have written a client(c1) and 3 servers (s1, s2 and s3) in python.
C1 will check if it is able to connect to s1. If yes, it will sleep for 2 mins. It will wake up again after 2 mins and will check if s1 is connectable. If no, then it will check s2. If s2 is listening then c1 will go to sleep for 2 mins. And this will keep on happening.
Now, my issue is, I can check s1 but not able use if else coding
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect(('111.111.1.1', 2222))
time.sleep(120)
except Exception as inst:
print("not ready1")
try:
s.connect(('11.22.22.2', 2212))
time.sleep(120)
except Exception as inst:
print("not ready2")
try:
s.connect(('1.1.1.33', 1234))
time.sleep(120)
except Exception as inst:
print("not ready3")
I want to achieve this using if else looping. And also make sure that this code executes infinite time. Right now, it will execute only once.
except Exception as e:is discouraged, it's not a good idea. I'm not sure I understand what the issue is, can you be more specific?