Creating a program for broadcast avahi

I am trying to write a program that outputs data that can be transmitted over a network with avahi. The documentation I was looking at seems like I need to register the service with dbus and then connect it to avahi, but the documentation for this is pretty scarce. Does anyone know of good documentation for this? I looked at them:

python-dbus: http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#exporting-objects

python-Avahi: http://www.amk.ca/diary/2007/04/rough_notes_python_and_dbus.html

I'm really not familiar with how avahi works at all, so any pointers would be helpful.

+5
source share
3

Avahi - "" ZeroConfig, DNS . Avahi "" . , , "" , .

0

, , , . .

avahi/dbus:

import avahi
import dbus
from time import sleep


class ServiceAnnouncer:
    def __init__(self, name, service, port, txt):
        bus = dbus.SystemBus()
        server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
        group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
                               avahi.DBUS_INTERFACE_ENTRY_GROUP)

        self._service_name = name
        index = 1
        while True:
            try:
                group.AddService(avahi.IF_UNSPEC, avahi.PROTO_INET, 0, self._service_name, service, '', '', port, avahi.string_array_to_txt_array(txt))
            except dbus.DBusException: # name collision -> rename
                index += 1
                self._service_name = '%s #%s' % (name, str(index))
            else:
                break

        group.Commit()

    def get_service_name(self):
        return self._service_name


if __name__ == '__main__':
    announcer = ServiceAnnouncer('Test Service', '_test._tcp', 12345, ['foo=bar', '42=true'])
    print announcer.get_service_name()

    sleep(42)

avahi-browse :

micke@els-mifr-03:~$ avahi-browse -a -v -t -r 
Server version: avahi 0.6.30; Host name: els-mifr-03.local
E Ifce Prot Name                                          Type                 Domain
+   eth0 IPv4 Test Service                                  _test._tcp           local
=   eth0 IPv4 Test Service                                  _test._tcp           local
   hostname = [els-mifr-03.local]
   address = [10.9.0.153]
   port = [12345]
   txt = ["42=true" "foo=bar"]
+10

Java, avahi4j, API ( ) Bonjour- . http://avahi4j.googlecode.com

-3
source

All Articles