[sugar] mdns/presence server from python

Trent Lloyd lathiat
Tue Feb 20 22:47:09 EST 2007


Hi Thibaut,

Couple main things that may be catching you out:

 a) You need an event loop of some form, i.e. glib
 b) If using the glib event loop you need to import dbus.glib (as well
    as dbus) to get the integration

Additionally you

You can find some additional documentation here:
http://www.avahi.org/wiki/ProgrammingDocs

Also these tools may be usefull:
http://www.avahi.org/browser/tags/release-0.5/avahi-utils

Various publish/browse examples before those tools were rewritten from
python to C, note however these (from 0.5) do not contain the 'flags'
paramter, this is usually found as the third argument to various
function calls, in most cases you can just pass 0, see the above
ProgrammingDocs to check the DBUS API for need to have flags (and
callbacks)

Cheers,
Trent

On Tue, Feb 20, 2007 at 10:06:03PM -0500, Thibaut Lamadon wrote:
>    Hi,
> 
>    I'm currently working on a network based activity for the OLPC. Today
>    we've met with Chris Blizzard who pointed me to this list.
> 
>    I try to use the mdns through python. More generally I'd like to get more
>    information and maybe some example (maybe some reference of code within
>    sugar to look at ) on how to use the presence server.
> 
>    Here is what I've tried, but it doesn't work (it's a stripped down version
>    of AvahiBookmark)
> 
>    class AvahiTest:
> 
>        def __init__(self, use_host_names):
>            self.bus = dbus.SystemBus()
>            self.server = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME,
>    avahi.DBUS_PATH_SERVER), avahi.DBUS_INTERFACE_SERVER)
>            self.version_string = self.server.GetVersionString()
>            self.browse_service_type ("_presence_olpc._tcp")
> 
>        def browse_service_type(self, stype):
>            domain="local"
>            browser = dbus.Interface(self.bus.get_object(avahi.DBUS_NAME,
>    self.server.ServiceBrowserNew (avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, stype,
>    domain, dbus.UInt32(0))), avahi.DBUS_INTERFACE_SERVICE_BROWSER)
>            browser.connect_to_signal('ItemNew', self.new_service)
>            browser.connect_to_signal('ItemRemove', self.remove_service)
> 
>        def new_service(self, interface, protocol, name, type, domain, flags):
>            print "new service!!!!"
> 
>        def remove_service(self, interface, protocol, name, type, domain):
>            print "service removed!!!"
> 
>    Thks
> 
>    Thibaut Lamadon

> _______________________________________________
> Sugar mailing list
> Sugar at laptop.org
> http://mailman.laptop.org/mailman/listinfo/sugar



More information about the Sugar-devel mailing list