View Full Version : getPeerAddress on localhost ?

17th February 2011, 23:32
I encounter a problem when run both client and server on one computer with an IP address 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 nor
that's why? how can i get the real ip

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

the result is:
received data from: :0

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