* MYBonjourBrowser: Added delegate (no methods for it yet, just for client use.)
* MYBonjourRegistration: Added +canonicalFormOfTXTRecordDictionary:.
* MYBonjourService: Added back-reference to browser.
* IPAddress: Added conversions to/from struct sockaddr.
6 Created by Jens Alfke on 2008-06-04.
7 This source file is test/example code, and is in the public domain.
10 from BLIP import Listener
17 class BLIPListenerTest(unittest.TestCase):
19 def testListener(self):
20 def handleConnection(conn):
21 logging.info("Got new connection: %r", conn)
22 conn.ListenerTestNumRequests = 0
24 def handleRequest(request):
25 logging.info("Got request!: %r",request)
26 request.connection.ListenerTestNumRequests += 1
28 assert len(body)<32768
29 assert request.contentType == 'application/octet-stream'
30 assert int(request['Size']) == len(body)
31 assert request['User-Agent'] != None
32 for i in xrange(0,len(request.body)):
33 assert ord(body[i]) == i%256
35 response = request.response
36 response.body = request.body
37 response['Content-Type'] = request.contentType
39 if request.connection.ListenerTestNumRequests >= 50:
40 request.connection.close()
42 listener = Listener(46353)
43 listener.onConnected = handleConnection
44 listener.onRequest = handleRequest
45 logging.info("Listener is waiting...")
49 except KeyboardInterrupt:
50 logging.info("KeyboardInterrupt")
52 if __name__ == '__main__':
53 logging.basicConfig(level=logging.INFO)