Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Socket local address and peer address
Qt 6.11 is out! See what's new in the release blog

Socket local address and peer address

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 9.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hpng
    wrote on last edited by
    #1

    Hello:
    What is the difference between local and peer address for the following:
    QHostAddress QAbstractSocket::localAddress () const
    QHostAddress QAbstractSocket::peerAddress () const

    I 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?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bobby
      wrote on last edited by
      #2

      "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.

      "Linux is not user-friendly." It is user-friendly. It is not ignorant-friendly and idiot-friendly.
      ---Source unknown

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hpng
        wrote on last edited by
        #3

        Thanks.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          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.

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved