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. QTcpSocket: selecting source interface using bind() for connection to remote host with connectToHost(): don't work, possible bug

QTcpSocket: selecting source interface using bind() for connection to remote host with connectToHost(): don't work, possible bug

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.9k 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.
  • S Offline
    S Offline
    sibislaw2
    wrote on last edited by
    #1

    Hi, i want to use certain source interface for connection to remote host. I have
    3 interfaces: eth0 (192.168.230.100), wlan0(10.0.9.100), and lo:

    Assuming mSocket is class member:

    @QTcpSocket mSocket;@

    And in constructor we use:

    @
    bool ret = mSocket.bind(QHostAddress("10.0.9.100"));
    @

    And then in timer we try to connect:

    @
    void CamComponent::tryToConnect()
    {
    mSocket.connectToHost(QHostAddress(CameraIpAddr), CameraPort);
    }
    @

    And after this i use TCPDUMP to view outgoing packets, and they dont have source IP 10.0.9.100. Using strace i had checked that Qt makes calls to:

    socket()
    bind()
    socket() <- this causes problem, it's QT internal problem
    connect()

    Is this any possibility to workaround this ? Maybe by using own sockets, creating descriptor and providing it to QTcpSocket by @QAbstractSocket::setSocketDescriptor@ ? Is this bug covers also QAbstractSocket::setSocketDescriptor ?

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hi.
      When you bind a socket using bind method then it randomly select a port number.Here i can see you didn't specify it.may be this cause an error because randomly selected port is not matched to your port.

      Is your CameraIpAddr same as 10.0.9.100 ?

      Be Cute

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sibislaw2
        wrote on last edited by
        #3

        It is not server socket. Addresses are randomly chosen by me, not real. The clue is that bind() dont work for connect to.

        1 Reply Last reply
        0
        • E Offline
          E Offline
          Eric Vialas
          wrote on last edited by
          #4

          Just to exclude any constructor overloading trap, have you tried:

          @
          bool ret=mSocket.bind(QHostAddress(QLatin1String("10.0.9.100")));
          @

          ?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sibislaw2
            wrote on last edited by
            #5

            I think it is related to BUG:

            https://bugreports.qt-project.org/browse/QTBUG-29732

            So my question, how to workaround this, or when bug will be fixed ?

            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