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. Static port for QTcpSocket
QtWS25 Last Chance

Static port for QTcpSocket

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtcpsocketport
3 Posts 2 Posters 1.9k 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.
  • R Offline
    R Offline
    reezeus
    wrote on 13 Nov 2015, 08:49 last edited by
    #1

    Hi

    I'm using a QTcpSocket to send data to stunnel.
    However in my stunnel config I need to setup a specific port for the localhost connection.

    In Qt I use:
    socket->connectToHost(ipBox->text(), portBox->text().toInt());

    It works, however when I print the port used:
    qDebug() << QString::number(socket_->localPort());

    it is not the value I have inputted. Actually the port changes everytime and even seems to be incremented.
    Do you know how to setup my QTcpSocket so it always uses the same port?

    Cheers

    1 Reply Last reply
    0
    • R Offline
      R Offline
      reezeus
      wrote on 13 Nov 2015, 16:34 last edited by
      #2

      To make it clear: when I say it works, I mean there's no other problem with the socket: the data is sent. But it never reaches the server since I can't configure the port I want to send the data through.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bsomervi
        wrote on 13 Nov 2015, 19:45 last edited by
        #3

        A TCP/IP connection utilizes two ports, the one you connect to on the remote end and a local port that is used for incoming data. The local port is an ephemeral port assigned by the operating system from the pool of free ephemeral port numbers. This is normal operation, you do not need to have a fixed local port because the the ephemeral port is sent to the remote end so that it knows how to reply to you the client.

        QAbstractSocket::peerPort() returns the remote port number.

        1 Reply Last reply
        0

        1/3

        13 Nov 2015, 08:49

        • Login

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