BROKEN COMMIT. Majority of code to handle closing has been added. Listeners do not close correctly.
3 # Not related to BLIP - just to aid in my understanding of what's going on
4 # Sends "Ping", waits for "Pong"
12 class asynchatPing(asynchat.async_chat):
13 def __init__(self, address):
14 asynchat.async_chat.__init__(self)
15 self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
17 self.set_terminator("Pong")
18 self.pingsSent = self.pongsGot = 0
19 self.donePing = self.donePong = False
21 def handle_connect(self):
24 def handle_close(self):
26 asynchat.async_chat.handle_close(self)
28 def collect_incoming_data(self, data):
32 def found_terminator(self):
33 """when we get a Pong"""
34 print "Received 'Pong'"
36 if self.pongsGot == kNumPings:
39 self.close_when_done()
46 if self.pingsSent == kNumPings:
52 while not self.donePing:
54 asyncore.loop(timeout=timeout, count=1)
58 if __name__ == '__main__':
59 ping = asynchatPing( ('localhost', 1337) )