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

Brad Howes howes at ll.mit.edu
Tue Mar 31 19:35:21 CEST 2009


On Mar 30, 2009, at 1:41 PM, Nathan Carter wrote:

> Yes I knew they were IPv6, but I'm not sure how to disable that.  That
> is, the code simply passes the QHostAddress object to
> QTcpSocket::connectToHost(), and that doesn't seem to have a way for
> me to specify the QAbstractSocket::NetworkLayerProtocol.  Furthermore,
> QHostAddress::protocol() is read-only.  What did you mean by "try
> disabling IPv6"?


I downloaded the QQ code to check it out. 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).

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)

HTH

Brad

-- 
Brad Howes
Group 42
MIT Lincoln Laboratory • 244 Wood St. • Lexington, MA 02173
Phone: 781.981.5292 • Fax: 781.981.3495 • Secretary: 781.981.7420








More information about the Qt-interest-old mailing list