PDA

View Full Version : getPeerAddress on localhost ?



bfyviolin
17th February 2011, 23:32
Hi
I encounter a problem when run both client and server on one computer with an IP address 10.0.0.3 acquired by DHCP.
On the server side, when i call QUdpSocket::getPeerAddress().toString() to get the ip address of client connected, it returns an empty string. Neither 10.0.0.3 nor 127.0.0.1.
that's why? how can i get the real ip 10.0.0.3?

code as follows:
printf("received data from: %s:%u\n",
qPrintable(udpSocket.peerAddress().toString()), udpSocket.peerPort() );

the result is:
received data from: :0

mcosta
18th February 2011, 14:45
From Qt docs


QHostAddress QAbstractSocket::peerAddress () const
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHostAddress::Null.

UDP is a Connection-less Protocol