Hi
I have a script that connects to a remote server. The code is below
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((remote_host,remote_port))
s.setblocking(False)
while True:
try:
data = s.recv(1024)
if not data:
break
pkt_type = ord(data[2]) # get pkt type
if pkt_type == Reset:
s.send(data)
if pkt_type == Authenticate:
processAuthenticate(s,data)
break
except:
pass
while(True)
.
.
.
I wait for reset and echo back to the server, then wait for an Authenticate packet, twiddle a few bit and echo that back to the server. Once this is done successfully I can now request data from the the server. This is done in the next while(true) loop.
Is this the best way of doing this. Sometimes when I run the script I get an error, what is the simplest way of handling the exception and preventing execuation of the next wile loop?
Thanks