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. QAbstractSocket::localPort() is different from QAbstractSocket::peerPort() in a connection?
Forum Updated to NodeBB v4.3 + New Features

QAbstractSocket::localPort() is different from QAbstractSocket::peerPort() in a connection?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 743 Views
  • 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.
  • P Offline
    P Offline
    Pauly
    wrote on last edited by
    #1

    I setup a QSslSocket between a client and a server, using a port number. At the server side when check I found the localPort() and peerPort() are different. The localPort() match to the port number I used and the peerPort() show some unknown number. How can that be?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dr.G
      wrote on last edited by
      #2

      This is because the peer dynamically allocates a high port for their connection attempt.

      As you know, ports below 1024 are reserved ports that can only be used by an administrative user (root / Administrator). Imagine your server was running on one of the reserved ports, and an unprivileged user wanted to connect to it. If the same port was used on both the server and the client side, then the unprivileged user would not be able to connect, because he couldn't open the port.

      Furthermore, imagine the user was using a browser on a server that also runs an http and a https server. In this instance, the user would have to disable the http and https servers if they wanted to browse the internet, which would be very impractical.

      Hence the ports are different.

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Pauly
        wrote on last edited by
        #3

        I see. Thanks a lot!

        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