Browse Source

Maybe even better andling of connection reset error

master
klonfish 8 years ago committed by klonfish
parent
commit
69b8086996
  1. 41
      wii-pair/daemon.py

41
wii-pair/daemon.py

@ -173,29 +173,32 @@ try:
conn, addr = s.accept() conn, addr = s.accept()
while True: while True:
try:
m = conn.recv(1) m = conn.recv(1)
except ConnectionResetError:
break
if len(m) == 0: if len(m) == 0:
conn.close() conn.close()
break break
r = b'' r = b''
for w in wiis: for w in wiis:
if w.pos_x is None: if w.pos_x is None:
v = -128 v = -128
else: else:
v = int(round(w.pos_x*100)) v = int(round(w.pos_x*100))
r += struct.pack('b', v) r += struct.pack('b', v)
if w.pos_y is None: if w.pos_y is None:
v = -128 v = -128
else: else:
v = int(round(w.pos_y*100)) v = int(round(w.pos_y*100))
r += struct.pack('b', v) r += struct.pack('b', v)
try: try:
conn.send(r) conn.send(r)
except ConnectionResetError: except ConnectionResetError:
break break
except (KeyboardInterrupt, SystemExit): except (KeyboardInterrupt, SystemExit):
t1.stop = True t1.stop = True
t2.stop = True t2.stop = True

Loading…
Cancel
Save