Results 1 to 2 of 2

Thread: Detect when a TCP Server dies

  1. #1
    Join Date
    Mar 2007
    Posts
    8
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Detect when a TCP Server dies

    I'm using a QTcpSocket to establish a connection with distant tcp servers. Can anyone give me an idea as to how I can tell if the server suddenly goes away? I'm not receiving any disconnect messages from the distant end and I can't be sure they will close the socket properly.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Detect when a TCP Server dies

    You can just try sending some data. If the other side is dead, you won't receive acknowledgements and the socket will timeout with error. Another way is to set the keep-alive option on the socket. This way the tcp/ip stack will ping the other side from time to time and terminate the connection if it doesn't respond.

Similar Threads

  1. How to ping a server ?
    By Nyphel in forum Newbie
    Replies: 2
    Last Post: 23rd April 2007, 11:27
  2. cannot connect to X server
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 18th April 2007, 14:22
  3. How a server can write "Hello" to a browser ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 1st December 2006, 14:43
  4. synching client readings to server output
    By OnionRingOfDoom in forum Qt Programming
    Replies: 14
    Last Post: 28th January 2006, 18:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.