[Qt-interest] QQ article on zeroconf/bonjour: code not working

Nathan Carter nathancarter5 at gmail.com
Tue Mar 31 20:15:37 CEST 2009


> I downloaded the QQ code to check it out.

Thanks for digging into it!

> There is a big problem in
> the client.cpp in that the connectToServer() slot only works with the
> first address entry found in the given hostInfo object (and the
> handling of errors does not help here). On my machine, the first entry
> found was an IPv6 address, but the fortuneserver is set up to only
> listen for IPv4 connection requests; see QTcpServer::listen(). The
> second address record has an IPv4 address, so that is the one that
> should be used here (and it works).

Ah, this seems easy to fix.  I can just loop through them until I find  
one with the right protocol, as you suggest in 3), below.

> The second problem is that the BonjourServiceResolver will emit N
> bonjourRecordResolved() signals where N is the number of interfaces
> through which the service may be found. On my laptop, I can see
> fortuneserver on my wired Ethernet interface and on two virtual ones
> setup by VMWare. No biggy, but when I click on the "Get Fortune"
> button, I should not get N requests for a fortune, but this is what is
> happening with the code. Here is what the code should *really* do:
>
>   1) Maintain a one-to-many relationship between the service name and
> resolved records
>   2) Try each resolved record until a connection is made, remember
> the correct one
>   3) Only use IPv4 addresses (check against QHostAddress::protocol()
> == QAbstractSocket::IPv4Protocol)

Right.  For the fortune client situation, one could conceivably ignore  
this latter problem, because it doesn't matter if you get three (or N)  
fortunes in rapid succession.  However, for a more serious  
application, one would need to do as you say above.  Something like  
this:
1. When any resolution arrives, if you're doing nothing, try to  
connect; if you're already trying to connect, queue it.
3. When a connection succeeds, forget the queue and use the connected  
one.
4. When a connection fails, throw it away and start trying to connect  
to the next one in queue, if there is one; if not, report failure to  
connect.

Do I seem to have interpreted your reply correctly?  Thanks again for  
the detailed information!

Nathan




More information about the Qt-interest-old mailing list