<br><br><div class="gmail_quote">On 10 August 2011 18:12, Daniel Stonier <span dir="ltr">&lt;<a href="mailto:d.stonier@gmail.com">d.stonier@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><br></div><div>Hi all,</div><div><br></div>I&#39;m having trouble getting avahi to detect collisions when trying to add a service with a name that is already existing. 
<div><br></div><div>For reference</div><div><br></div><div> - Platform is ubuntu 10.04</div><div> - I&#39;m using exactly the script at <a href="http://avahi.org/wiki/PythonPublishExample" target="_blank">http://avahi.org/wiki/PythonPublishExample</a></div>

<div> - I have two shells open, and run the same script in each shell</div><div><br></div><div>Results:</div><div><br></div><div>The first execution starts the Demo Service and can be seen when running `avahi-browse -a`.</div>

<div><br></div><div>The second execution appears to go smoothly, the group state change goes through &#39;ENTRY_GROUP_REGISTERING&#39;-&gt;&#39;ENTRY_GROUP_ESTABLISHED&#39;, but nothing appears on the avahi browser. I would have expected a group state change to &#39;ENTRY_GROUP_COLLISION&#39; here.</div>

<div><br></div><div>Additionally, the underlying avahi library is doing collisions properly - I can check that by running </div><div><br></div><div><div>&gt; avahi-publish -s &#39;Demo Service&#39; _demo._tcp 1234</div><div>

&gt; Failed to add service: Local name collision</div></div><div><br></div><div>Is there a problem with python-avahi and dbus in handling the local name collisions?</div><div><br></div><div>Regards,</div><div>Daniel Stonier.</div>


</blockquote></div><br>Discovered a little more enlightenment on this problem - you can detect this in python via exceptions around the AddService call:<div><br></div><div>****************************************************************************************</div>
<div><br></div><div><div>        try:</div><div>            self._group.AddService(</div><div>                avahi.IF_UNSPEC,</div><div>                avahi.PROTO_UNSPEC,</div><div>                dbus.UInt32(0),</div><div>
                <a href="http://service.name">service.name</a>, </div><div>                service.service_type,</div><div>                service.domain,</div><div>                service.hostname + &quot;.&quot; + service.domain,</div>
<div>                dbus.UInt16(str(service.port)),</div><div>                avahi.string_array_to_txt_array(service.description))</div><div>            self._group.Commit()</div><div>        except dbus.exceptions.DBusException as e:</div>
<div>            # is there  a better way to detect this?</div><div>            if e.get_dbus_name() == avahi.DBUS_NAME + &quot;.CollisionError&quot;:</div><div><br></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>
****************************************************************************************</div></div><div><br></div><div>Thats awkward. Is there a reason this doesn&#39;t go to the group-state_changed callback (when checking ENTRY_GROUP_COLLISION) along with collisions from other computers on the lan?</div>
<div><br></div><div>I currently proceed to call GetAlternativeServiceName(...) when this exception throws.   Is there a better way to handle these?</div><div><br></div><div>Cheers,<br>Daniel.</div><meta http-equiv="content-type" content="text/html; charset=utf-8">
</div>