Need to catch socket error while sending data, my code catches error the second time after disconnection, first time send is not throwing exception. Is this the right way to do it. Any way that I can achieve it?
def send_message(msg, inst):
msg = msg.encode(FORMAT)
try:
client[inst].send(msg)
print(f"Socket error {msg} {inst}")
except socket.error:
client[inst].close()
print(f"Connection closed, moving on {msg} {inst}")
client[inst+1].send(msg)