pythonzeroconf

How to send data using Python-Zeroconf


I saw a tutorial on Python-Zeroconf.

The tutorial showed how to create a Python-Zeroconf listener so I know how to receive data.

This is below.

from zeroconf import ServiceBrowser, Zeroconf

class MyListener:

    def remove_service(self, zeroconf, type, name):
        print("Service %s removed" % (name,))

    def add_service(self, zeroconf, type, name):
        info = zeroconf.get_service_info(type, name)
        print("Service %s added, service info: %s" % (name, info))


zeroconf = Zeroconf()
listener = MyListener()
browser = ServiceBrowser(zeroconf, "_http._tcp.local.", listener)
try:
    input("Press enter to exit...\n\n")
finally:
    zeroconf.close()

But it didn't seem to write how to send the data. Is it possible to send data using Python-Zeroconf? How can I send it?


Solution

  • Zeroconf is about letting a client find a service and which port to connect to, not the actual data transmission. There are tutorials on the net about creating simple clients and servers in python. Here is one Python socket programming.