title: Accessing Avahi through dbus-send
body: <p>In the process of hacking around with <code>dbus-monitor</code>, I tried connecting to the Avahi daemon:</p>
  
  <pre><code>$ dbus-monitor --system \
    "type='signal',interface='org.freedesktop.Avahi.Server',member='StateChanged'"
  </code></pre>
  
  <p>This will respond to changes in the state of the Avahi daemon.</p>
  
  <pre><code>$ sudo restart avahi-daemon
  
  signal sender=org.freedesktop.DBus -&gt; 
           dest=:1.315 
           serial=2
           path=/org/freedesktop/DBus;
           interface=org.freedesktop.DBus;
           member=NameAcquired
      string ":1.315"
  
  signal sender=:1.318 -&gt;
           dest=(null destination)
           serial=4
           path=/;
           interface=org.freedesktop.Avahi.Server; 
           member=StateChanged
      int32 1
      string "org.freedesktop.Avahi.Success"
  
  signal sender=:1.318 -&gt; 
           dest=(null destination)
           serial=13
           path=/;
           interface=org.freedesktop.Avahi.Server;
           member=StateChanged
      int32 2
      string "org.freedesktop.Avahi.Success"
  </code></pre>
  
  <p>However, I cannot browse services like this.</p>
  
  <pre><code>$ dbus-send --system --dest=org.freedesktop.Avahi --print-reply \
      / org.freedesktop.Avahi.Server.ServiceBrowserNew \
      int32:-1 int32:-1 string:'_http._tcp' string:'local' uint32:0
  
  method return sender=:1.345 -&gt; 
           dest=:1.354
           reply_serial=2
      object path "/Client5/ServiceBrowser1"
  
  $ dbus-monitor --system \
      "type='signal',interface='org.freedesktop.Avahi.ServiceBrowser'"
  </code></pre>
  
  <p>As far as I understand, this should respond to new/removed http service
  instances, but it does not. </p>
  
  <p>Why?</p>
  
  <h3>Update:</h3>
  
  <p>Executing the equivalent of the above shell commands with the python and c APIs 
  worked as expected. However, they could not connect to a ServiceBrowser which I
  had constructed using <code>dbus-send</code> and I could not use <code>dbus-monitor</code> to listen
  to a ServiceBrowser they constructed.</p>
  
  <p>At this point, my best guesses are:</p>
  
  <ol>
  <li>Once the connection is closed (by the termination of the <code>dbus-send</code> command), 
  the ServiceBrowser I created is destroyed. However this does not explain why 
  <code>dbus-monitor</code> is unable to connect to a ServiceBrowser which is in active
  communication with my python script.</li>
  <li>The signals from the ServiceBrowser are emitted only to the connection which
  instantiated them.</li>
  </ol>