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 cannot cancelled during QAbstractSocket::ConnectingState! BUG??!!
Forum Updated to NodeBB v4.3 + New Features

QTcpSocket cannot cancelled during QAbstractSocket::ConnectingState! BUG??!!

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 2.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.
  • J Offline
    J Offline
    jackmack
    wrote on last edited by
    #1

    Hi,

    I'm using Qt 4.8.6 and Qt 5.3.0 with VS2010, Win7. Ob both Qt version the same issue/bug occurs!

    I'm using QTcpSocket to connect as client to a running server - no problems. But when the server is down/not running, the QTcpSocket::connectToHost() enters following states:

    1. QAbstractSocket::HostLookupState
    2. QAbstractSocket::ConnectingState
      (Staying there for awhile...)
    3. QAbstractSocket::UnconnectedState
    4. Error with QAbstractSocket::NetworkError

    If now I start the server again immendiately a client is showed as connected - but it's not my client! I cannot send data to the server. Now when I call QTcpSocket::connectToHost() again the server schows me that the first connection is disconnected and a new one is connected. Now I can send data to the server about that new one!

    That's strange or should I say: It's a bug! It seems in background the connecting attempt is running further.

    The same behaviour is when after
    ...
    2. QAbstractSocket::ConnectingState
    (Staying there for awhile...)
    --> Here call QTcpSocket::disconnectFromHost() or abort() or close() or reset()!

    It seems the connecting attempt cannot be cancelled! This spits me into my reconnect mechanism and I cannot make sure it works correct :-(

    Any suggestions?

    Thanks a lot

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      AFAIK, there's a 30s connection timeout, are you trying to connect again in that delay ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jackmack
        wrote on last edited by
        #3

        He,

        yes. If I'm waiting for 30s and more after error with QAbstractSocket::NetworkError occured and try again it seems to work.

        But the problem is:
        If the server is coming up earlier, e.g. 10s after I got QAbstractSocket::NetworkError on client side, on server side the background attempt is already connected (wrong one).

        Strange, that nobody has recognized that issue!

        I need a function to cancel the background attempt. I tried also ::closesocket() with a socketdescriptor (socketDescriptor() in error() slot), also WSACleanup(), WSAShutdown(). Nothing helped.

        Strange also that after WSAShutdown() the QNetwork module works further. For windows there is qnativesocketengine_win.cpp which using winsock2.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jackmack
          wrote on last edited by
          #4

          Added:

          Now when the server is down/not running, the QTcpSocket::connectToHost() enters following states:

          1. QAbstractSocket::HostLookupState
          2. QAbstractSocket::ConnectingState
            (Staying there for only 3s)
          3. QAbstractSocket::UnconnectedState
          4. Error with QAbstractSocket::ConnectionRefusedError

          Definitely it depends of the OS :-(
          Ohh, I have a very very bad feeling...

          Sometimes in the stateChanged() slot with state = UnconnectedState I have access to a valid socket descriptor with socketDescriptor(). Calling ::closesocket(), shutdown()... nothing helps. The background attempt to connect is still alive.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What OSs are you using ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jackmack
              wrote on last edited by
              #6

              Windows7, 64Bit

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Can you test with a more recent version of Qt ? e.g 5.5.1 or even 5.6 beta ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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