Created
January 27, 2017 14:01
-
-
Save marciogranzotto/3548460b642ff17bbcbad2ae4ca164bc to your computer and use it in GitHub Desktop.
Zeroconf example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" Example of announcing a service (in this case, a fake HTTP server) """ | |
import logging | |
import socket | |
import sys | |
from time import sleep | |
from zeroconf import ServiceInfo, Zeroconf | |
if __name__ == '__main__': | |
logging.basicConfig(level=logging.DEBUG) | |
if len(sys.argv) > 1: | |
assert sys.argv[1:] == ['--debug'] | |
logging.getLogger('zeroconf').setLevel(logging.DEBUG) | |
desc = {'path': '/~paulsm/'} | |
info = ServiceInfo("_http._tcp.local.", | |
"Paul's Test Web Site._http._tcp.local.", | |
socket.inet_aton("127.0.0.1"), 80, 0, 0, | |
desc, "ash-2.local.") | |
zeroconf = Zeroconf() | |
print("Registration of a service, press Ctrl-C to exit...") | |
zeroconf.register_service(info) | |
try: | |
while True: | |
sleep(0.1) | |
except KeyboardInterrupt: | |
pass | |
finally: | |
print("Unregistering...") | |
zeroconf.unregister_service(info) | |
zeroconf.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment