Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.
Qt 6.11 is out! See what's new in the release blog

Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 3 Posters 867 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
    sdl1
    wrote on last edited by
    #1

    Re: QTcpSocket doesn't timeout

    Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.

    sdl

    A JonBJ 2 Replies Last reply
    0
    • S sdl1

      Re: QTcpSocket doesn't timeout

      Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.

      sdl

      A Offline
      A Offline
      ambershark
      wrote on last edited by ambershark
      #2

      @sdl1 The OS doesn't always report a failed network connection. I don't think this is a Qt thing but an underlying sockets thing.

      The only real way to be sure it is still connected is a periodic heartbeat check. Then when it fails you know your connection is dead and can close/reconnect.

      For my programs that I've done this I always make sure it misses a few heartbeats before I call it dead to account for packet loss and slow connections. The downside to that is you may think it's alive for a while. Mine was about 30s or so before I called it gone. What I did was had an indicator in the status bar (just a color circle/light) it was green when it was good, yellow when it had missed a heartbeat, orange when it missed multiples, and red would be disconnected.

      This was with raw sockets and not using Qt, so it's really not a Qt issue. It was before I used Qt.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      2
      • S sdl1

        Re: QTcpSocket doesn't timeout

        Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.

        sdl

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @sdl1 , @ambershark

        Yes, connections may timeout or may never timeout. Can depend on client/server/OS/implementation...

        Be aware that @ambershark's suggestion of "heartbeat" is a double-edged sword, depending on what you are trying to achieve. If your objective is to see if the other side has "gone away" it is suitable. But if your objective is actually to allow timeout & connection close (and detect it) it will actually prevent (as far as possible) the connection from ever timing out as you keep sending packets which will maintain the connection so it doesn't get a chance to timeout close!

        A 1 Reply Last reply
        2
        • JonBJ JonB

          @sdl1 , @ambershark

          Yes, connections may timeout or may never timeout. Can depend on client/server/OS/implementation...

          Be aware that @ambershark's suggestion of "heartbeat" is a double-edged sword, depending on what you are trying to achieve. If your objective is to see if the other side has "gone away" it is suitable. But if your objective is actually to allow timeout & connection close (and detect it) it will actually prevent (as far as possible) the connection from ever timing out as you keep sending packets which will maintain the connection so it doesn't get a chance to timeout close!

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @JonB said in Has this ever been solved? I'm having the same issue. Usually, a TCP connection will timeout after some period of time, but I've left mine for hours and it never times out.:

          But if your objective is actually to allow timeout & connection close (and detect it)

          Yep that's true. My app where I did that was a real time stock trading platform. It needed to detect if the other side had gone away and let the user know or get it back ASAP.

          Financial people get very grumpy when they don't have real time data. :D They are not understanding of socket limitations.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          3

          • Login

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