QTcpSocket detecting dead peers immediately

  • 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...

  • 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.

  • Hi,

    you can use the TCP_KEEAPLIVE options.

  • @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..

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

  • @mcosta said:


    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)

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.