summaryrefslogtreecommitdiff
path: root/examples/registration.py
blob: 50d53c1b1cdf7fd41478b79268a1044d5c6d0dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python

""" Example of announcing a service (in this case, a fake HTTP server) """

import socket

from six.moves import input

from zeroconf import ServiceInfo, Zeroconf

desc = {'path': '/~paulsm/'}

info = ServiceInfo("_http._tcp.local.",
                   "Paul's Test Web Site._http._tcp.local.",
                   socket.inet_aton("10.0.1.2"), 80, 0, 0,
                   desc, "ash-2.local.")

zeroconf = Zeroconf()
print("Registration of a service...")
zeroconf.register_service(info)
try:
    input("Waiting (press Enter to exit)...")
finally:
    print("Unregistering...")
    zeroconf.unregister_service(info)
    zeroconf.close()