PDA

View Full Version : QAbstractSocket::disconnected () signal does not emit when switch is disconnected



babu198649
1st April 2010, 08:58
Hi
I am running Qt client application which connects to the remote server. When i remove the remote system from the network by unplugging the lan from the switch, i execpt the QAbstractSocket::disconnected () signal to be emitted, but it is not happening, But if the close the application instead of unplugging the remote system from lan, every thing is fine. Could any one point out the error.

Thanks

wysota
1st April 2010, 11:12
Well then don't expect it. One system has no way of knowing that another system went down unless the other end tells it so. But if you just unplug the cable there is no way of doing that, is it? Only if the two systems are connected directly, you can determine that the cable was unplugged. But then according to TCP specifications (if we are talking about TCP) this is not enough to break the connection because the traffic may be routed elsewhere or the old route may become available again. TCP connections timeout after about 10-20 minutes and that's the only more or less reliable way of telling that something wrong is going on. What you can do is to send keep-alive-like packets and expect to receive them within a specified period of time. If you don't receive one within the specified parameters, you consider the connection broken.

babu198649
1st April 2010, 17:16
Do you mean that the keep-alive-like should be implemented in the application layer, or does the QAbstractSocket::KeepAliveOption(I dont know what it is) has anything to do with it.


if we are talking about TCP
yes

Thanks for the info, that a tcp only knows about the disconnecivity(in case of unplugging) only after 10-20 minutes. In the ip-header field there is a time-to-live field, is it possible to control the field to have less timeouts and know about the connectivity instead of waiting for 10-20 minutes..

wysota
1st April 2010, 17:49
Thanks for the info, that a tcp only knows about the disconnecivity(in case of unplugging) only after 10-20 minutes. In the ip-header field there is a time-to-live field, is it possible to control the field to have less timeouts and know about the connectivity instead of waiting for 10-20 minutes..

TTL is not about "time", it's about number of hops a packet makes between the source and the destination of the packet.

babu198649
30th June 2010, 10:38
How about sending icmp(ping) packets if there is no read or write operation performed for certain period of time, on the socket, and if the icmp response fails, disconnecting the socket.

Can QHostInfo be used for sending icmp packets.

wysota
9th July 2010, 09:49
ICMP can fail for many reasons, that's one thing. Another is that ICMP packets require superuser access to the system (as all raw packets do). You can only rely on your system reporting (and notifying its environment) that a network interface was unpluged but it is not an equivalent of "losing" the connection as you can plug the cable back to the socket and the TCP connection should resume its job.

vipw
24th February 2012, 12:17
Where did the 10-20 minutes numbers come from?

I think the relevant value is the tcp keepalive idle time, which defaults to 2 hours. Here's some info about it: http://www.starquest.com/Supportdocs/techStarLicense/SL002_TCPKeepAlive.shtml

It's not clear to me if SO_KEEPALIVE is even enabled by default on most TCP stacks. It isn't on Windows, for example.

On some platforms the idle time of a socket can be set with setsockopt() and TCP_KEEPIDLE, but that isn't supported in the Qt API.

Is there some other mechanism that would lead to the TCP socket timing out sooner? Will it ever timeout on Windows if QAbstractSocket::KeepAliveOption isn't set?