util/Zeroconf.py
changeset 1826 91796f408540
parent 1783 3311eea28d56
child 1828 396da88d7b5c
equal deleted inserted replaced
1825:bcb50e736a46 1826:91796f408540
    72 # 0.04 update - added some unit tests
    72 # 0.04 update - added some unit tests
    73 #                  added __ne__ adjuncts where required
    73 #                  added __ne__ adjuncts where required
    74 #                  ensure names end in '.local.'
    74 #                  ensure names end in '.local.'
    75 #                  timeout on receiving socket for clean shutdown
    75 #                  timeout on receiving socket for clean shutdown
    76 
    76 
       
    77 
       
    78 from __future__ import print_function
    77 import string
    79 import string
    78 import time
    80 import time
    79 import struct
    81 import struct
    80 import socket
    82 import socket
    81 import threading
    83 import threading
  1562 # Test a few module features, including service registration, service
  1564 # Test a few module features, including service registration, service
  1563 # query (for Zoe), and service unregistration.
  1565 # query (for Zoe), and service unregistration.
  1564 
  1566 
  1565 
  1567 
  1566 if __name__ == '__main__':
  1568 if __name__ == '__main__':
  1567     print "Multicast DNS Service Discovery for Python, version", __version__
  1569     print("Multicast DNS Service Discovery for Python, version", __version__)
  1568     r = Zeroconf()
  1570     r = Zeroconf()
  1569     print "1. Testing registration of a service..."
  1571     print("1. Testing registration of a service...")
  1570     desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'}
  1572     desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'}
  1571     info = ServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.", socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc)
  1573     info = ServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.", socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc)
  1572     print "   Registering service..."
  1574     print("   Registering service...")
  1573     r.registerService(info)
  1575     r.registerService(info)
  1574     print "   Registration done."
  1576     print("   Registration done.")
  1575     print "2. Testing query of service information..."
  1577     print("2. Testing query of service information...")
  1576     print "   Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local."))
  1578     print("   Getting ZOE service:", str(r.getServiceInfo("_http._tcp.local.", "ZOE._http._tcp.local.")))
  1577     print "   Query done."
  1579     print("   Query done.")
  1578     print "3. Testing query of own service..."
  1580     print("3. Testing query of own service...")
  1579     print "   Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local."))
  1581     print("   Getting self:", str(r.getServiceInfo("_http._tcp.local.", "My Service Name._http._tcp.local.")))
  1580     print "   Query done."
  1582     print("   Query done.")
  1581     print "4. Testing unregister of service information..."
  1583     print("4. Testing unregister of service information...")
  1582     r.unregisterService(info)
  1584     r.unregisterService(info)
  1583     print "   Unregister done."
  1585     print("   Unregister done.")
  1584     r.close()
  1586     r.close()