[Qt-interest] QAbstractSocket::waitForReadyRead() is not working
Patric
userqt at gmail.com
Sun May 31 16:49:01 CEST 2009
I have just searched and found that I have misunderstood the purpose of this
method.
According to this thread
http://www.qtcentre.org/forum/f-newbie-4/t-qudpsocket-binding-doesnt-work-19755.html
the bind method is just giving an inteface to my socket and the
connectToHost is just making the need of specifing the peer address in the
write function redundant.
----------------------------- quote
It all becomes clear once you understand how UDP works and how ::bind and
::connect() work. UDP is connectionless protocol therefore with a single
socket you can reach multiple targets and receive data from multiple
sources. ::bind (and QUdpSocket::bind()) associates an address (interface
and UDP port) with your (local) socket. Since this moment you can start
receiving data on the socket because the operating system knows that if data
reaches a specific UDP port on a specific network interface, it should be
forwarded to your socket.
As UDP is a connectionless protocol it is obvious that ::connect() (and
QAbstractSocket::connectToHost()) doesn't do any connecting. In particular
no data gets exchanged in the network. All it does is that it associates
your socket with a default remote address. Thanks to that you don't have to
pass the peer address to functions for receiving or sending a datagram -
instead the address you passed to ::connect() will be used. You can still
receive datagrams from other addresses and you can still send datagrams to
other addresses. The only difference is that you will have to specify peer
addresses while sending or receiving if you don't call ::connect().
----------------------------- quote
But I don't understand two things here.
First, even if we use connectToHost to specify the peer address, we still
have to call the writeDatagram method with IP Address and port.
And second, (this approach is used in the example of QUdpSocket), what means
to bind without an Address, I mean to use
udpsocket.bind(162);
for example. From the documentation it is clear that in this case the
QHostAddress::Any is used. But what means Any ? the purpose of bind is to
give an interface to the socket, what will happen if we specify IP Address
to Any ? Which is the default behaviour of the overloaded bind function,
when only Port is passed.
Regards,
Patric
----- Original Message -----
From: "Thiago Macieira" <thiago.macieira at trolltech.com>
To: <qt-interest at trolltech.com>
Sent: Sunday, May 31, 2009 5:17 PM
Subject: Re: [Qt-interest] QAbstractSocket::waitForReadyRead() is not
working
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4098 (20090522) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
__________ Information from ESET NOD32 Antivirus, version of virus signature database 4098 (20090522) __________
The message was checked by ESET NOD32 Antivirus.
http://www.eset.com
More information about the Qt-interest-old
mailing list