diff options
author | Ruben Undheim <ruben.undheim@gmail.com> | 2019-10-18 22:25:53 +0200 |
---|---|---|
committer | Ruben Undheim <ruben.undheim@gmail.com> | 2019-10-18 22:25:53 +0200 |
commit | be941ab1c6f24ac535438e84c41eb1b77ec2c01a (patch) | |
tree | 4bd006c48b272bf7cbf4f1c2b26c754a0d97396d /examples | |
parent | 0bd2d1af7b88b0c1889123b2bef286b09108a93f (diff) |
New upstream version 0.23.0
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/browser.py | 5 | ||||
-rwxr-xr-x | examples/registration.py | 12 | ||||
-rwxr-xr-x | examples/self_test.py | 13 |
3 files changed, 19 insertions, 11 deletions
diff --git a/examples/browser.py b/examples/browser.py index 17a778a..8b4fd5e 100755 --- a/examples/browser.py +++ b/examples/browser.py @@ -12,14 +12,15 @@ from zeroconf import ServiceBrowser, ServiceStateChange, Zeroconf def on_service_state_change( - zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange, + zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange ) -> None: print("Service %s of type %s state changed: %s" % (name, service_type, state_change)) if state_change is ServiceStateChange.Added: info = zeroconf.get_service_info(service_type, name) if info: - print(" Address: %s:%d" % (socket.inet_ntoa(cast(bytes, info.address)), cast(int, info.port))) + addresses = ["%s:%d" % (socket.inet_ntoa(addr), cast(int, info.port)) for addr in info.addresses] + print(" Addresses: %s" % ", ".join(addresses)) print(" Weight: %d, priority: %d" % (info.weight, info.priority)) print(" Server: %s" % (info.server,)) if info.properties: diff --git a/examples/registration.py b/examples/registration.py index ad707c2..bda55b8 100755 --- a/examples/registration.py +++ b/examples/registration.py @@ -17,10 +17,14 @@ if __name__ == '__main__': 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.") + info = ServiceInfo( + "_http._tcp.local.", + "Paul's Test Web Site._http._tcp.local.", + addresses=[socket.inet_aton("127.0.0.1")], + port=80, + properties=desc, + server="ash-2.local.", + ) zeroconf = Zeroconf() print("Registration of a service, press Ctrl-C to exit...") diff --git a/examples/self_test.py b/examples/self_test.py index c5b56ec..62e3257 100755 --- a/examples/self_test.py +++ b/examples/self_test.py @@ -18,15 +18,18 @@ if __name__ == '__main__': r = Zeroconf() print("1. Testing registration of a service...") desc = {'version': '0.10', 'a': 'test value', 'b': 'another value'} - info = ServiceInfo("_http._tcp.local.", - "My Service Name._http._tcp.local.", - socket.inet_aton("127.0.0.1"), 1234, 0, 0, desc) + info = ServiceInfo( + "_http._tcp.local.", + "My Service Name._http._tcp.local.", + addresses=[socket.inet_aton("127.0.0.1")], + port=1234, + properties=desc, + ) print(" Registering service...") r.register_service(info) print(" Registration done.") print("2. Testing query of service information...") - print(" Getting ZOE service: %s" % ( - r.get_service_info("_http._tcp.local.", "ZOE._http._tcp.local."))) + print(" Getting ZOE service: %s" % (r.get_service_info("_http._tcp.local.", "ZOE._http._tcp.local."))) print(" Query done.") print("3. Testing query of own service...") queried_info = r.get_service_info("_http._tcp.local.", "My Service Name._http._tcp.local.") |