Socket local address and peer address
-
Hello:
What is the difference between local and peer address for the following:
QHostAddress QAbstractSocket::localAddress () const
QHostAddress QAbstractSocket::peerAddress () constI assume peer address is IP address of host of the other side of the connection, while
local address is the IP address on my computer where I am running / developing an app using
the above socket object, right? -
"Looking at the documentation":http://doc.qt.nokia.com/4.7-snapshot/qabstractsocket.html#peerAddress it seems that peeraddress() checks the connectivity state before trying to return the address.
This would be useful for a "if connected, who are we connected to" scenario vs "Localaddress":http://doc.qt.nokia.com/4.7-snapshot/qabstractsocket.html#localAddress which will return your address if you have the ability to make a socket.
-
The doc is quite clear about that:
bq. "QAbstractSocket::localAddress() ":http://doc.qt.nokia.com/4.7/qabstractsocket.html#localAddress:
Returns the host address of the local socket if available; otherwise returns QHostAddress::Null.bq. "QAbstractSocket::peerAddress() ":http://doc.qt.nokia.com/4.7/qabstractsocket.html#peerAddress:
Returns the address of the connected peer if the socket is in ConnectedState; otherwise returns QHostAddress::Null.Peer in network context always means the other side of the connection (not necessarily remote - you can connect to your local machine too!). So you're right with your assumptions.