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. [QtNetwork] How to identify dead connection
Forum Updated to NodeBB v4.3 + New Features

[QtNetwork] How to identify dead connection

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.8k 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.
  • B Offline
    B Offline
    Baca48
    wrote on last edited by
    #1

    Hi! Is there an implemented method in Qt to check if the connection is working or not? I'm realised that if client losts internet connection, server doesn't get any information about it. Do I have to implement ping operation? Thx for the answer.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      What do you use? QNAM or *Socket classes?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Baca48
        wrote on last edited by
        #3

        I'm using QTcpSocket and QTcpServer.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          Look at

          bq. void QAbstractSocket::stateChanged ( QAbstractSocket::SocketState socketState ) [signal]

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Baca48
            wrote on last edited by
            #5

            I thought about that and it was the first thing I checked. It changes only when I close the app without disconnecting but it doesn't work when you e.g. plug out network cable.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DenisKormalev
              wrote on last edited by
              #6

              It should work. As additional check you can add timeouts to your read/write waits (if you use them) and check after it for failure.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dangelog
                wrote on last edited by
                #7

                The "right" way is to implement your own keepalive mechanism for your protocol (or use reasonable defaults). Otherwise you could try enabling the TCP keepalive mechanism, or use QtMobility's QSystemNetworkInfo to get notifications when the status of the networking changes, as discussed in this thread: http://developer.qt.nokia.com/forums/viewthread/2420

                Software Engineer
                KDAB (UK) Ltd., a KDAB Group company

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  Baca48
                  wrote on last edited by
                  #8

                  I've decided to write my own keepalive service. Topic can be closed. Thanks for help :)

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tobias.hunger
                    wrote on last edited by
                    #9

                    It does work, but it waits for a usually rather long time out.

                    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