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 detecting dead peers immediately

QTcpSocket detecting dead peers immediately

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.4k 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.
  • M Offline
    M Offline
    Misty River
    wrote on last edited by
    #1

    Hello,

    How can I detect when one end of a socket is dead immediately? I have a client and a server and when I pull the chord on the client side it can take up to 1-2 minutes before the server notices that the client is dead and close the socket.. I would like the server to notice it within like a second...

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      When using TCP I think you can detect whether the receiving socket is still alive by checking the status of the write request. If write returns -1, then check for the error, and you should be able to detect a host is down. Note that there's also an error signal.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      M 1 Reply Last reply
      0
      • M Offline
        M Offline
        mcosta
        wrote on last edited by
        #3

        Hi,

        you can use the TCP_KEEAPLIVE options.

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        M 1 Reply Last reply
        0
        • JohanSoloJ JohanSolo

          When using TCP I think you can detect whether the receiving socket is still alive by checking the status of the write request. If write returns -1, then check for the error, and you should be able to detect a host is down. Note that there's also an error signal.

          M Offline
          M Offline
          Misty River
          wrote on last edited by
          #4

          @JohanSolo I have tried both of what you're sayin.. write doesn't return -1 on the server side... the socket is still in connected state and there's no error signal being sent... after I send a packet to a dead host it takes about 30 seconds and then it closes... but it's way too long I need it to be down to 1-2 seconds..

          1 Reply Last reply
          0
          • M mcosta

            Hi,

            you can use the TCP_KEEAPLIVE options.

            M Offline
            M Offline
            Misty River
            wrote on last edited by
            #5

            @mcosta I have tried setting it to 0 but it doesn't appear to have any effect on windows...

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              @mcosta said:

              TCP_KEEAPLIVE

              You have to enable KeepAlive (so set to 1) and also change the keep alive interval (I think you have to use native API for that)

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              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