comparison pytouhou/network.py @ 477:e71b1bcf952a

Wait a bit for incoming messages...
author Thibaut Girka <thib@sitedethib.com>
date Wed, 28 Dec 2011 19:07:37 +0100
parents 9d4d52793eca
children 884ca91b0854
comparison
equal deleted inserted replaced
476:44c5e7d4b615 477:e71b1bcf952a
10 self.keystate = 0 10 self.keystate = 0
11 self.old_keystate = 0 11 self.old_keystate = 0
12 12
13 self.remote_addr = dest 13 self.remote_addr = dest
14 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) 14 self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
15 self.sock.setblocking(0)
16 self.sock.bind(('', port)) 15 self.sock.bind(('', port))
17 16
18 17
19 def read_messages(self): 18 def read_messages(self):
20 messages = [] 19 messages = []
21 20
22 rlist, wlist, xlist = select([self.sock], [], [], 0) 21 rlist, wlist, xlist = select([self.sock], [], [], 1./60.)
23 while rlist: 22 while rlist:
24 msg, addr = rlist[0].recvfrom(MSG_STRUCT.size) 23 msg, addr = rlist[0].recvfrom(MSG_STRUCT.size)
25 # Check whether the message comes from the right address 24 # Check whether the message comes from the right address
26 if self.remote_addr is None or addr == self.remote_addr: 25 if self.remote_addr is None or addr == self.remote_addr:
27 self.remote_addr = addr 26 self.remote_addr = addr