Skip to content

Commit 703d971

Browse files
smcvjstasiak
authored andcommitted
examples: Add an example of resolving a known service by service name
To use: * `avahi-publish-service -s 'My Service Name' _test._tcp 0` * `./examples/resolver.py` should print a `ServiceInfo` * Kill the `avahi-publish-service` process * `./examples/resolver.py` should print `None` Signed-off-by: Simon McVittie <[email protected]>
1 parent 374f45b commit 703d971

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/resolver.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python3
2+
3+
""" Example of resolving a service with a known name """
4+
5+
import logging
6+
import sys
7+
8+
from zeroconf import Zeroconf
9+
10+
TYPE = '_test._tcp.local.'
11+
NAME = 'My Service Name'
12+
13+
if __name__ == '__main__':
14+
logging.basicConfig(level=logging.DEBUG)
15+
if len(sys.argv) > 1:
16+
assert sys.argv[1:] == ['--debug']
17+
logging.getLogger('zeroconf').setLevel(logging.DEBUG)
18+
19+
zeroconf = Zeroconf()
20+
21+
try:
22+
print(zeroconf.get_service_info(TYPE, NAME + '.' + TYPE))
23+
finally:
24+
zeroconf.close()

0 commit comments

Comments
 (0)