Results 1 to 7 of 7

Thread: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    babu198649 (1st April 2010)

  4. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

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

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    Quote Originally Posted by babu198649 View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    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.

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Feb 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QAbstractSocket::disconnected () signal does not emit when switch is disconnected

    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...eepAlive.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?

Similar Threads

  1. Emit signal from thread
    By sisco in forum Newbie
    Replies: 2
    Last Post: 26th November 2009, 13:32
  2. QFtp disconnected from server
    By cutie.monkey in forum Newbie
    Replies: 5
    Last Post: 20th May 2009, 11:46
  3. how to know which button emit the signal?
    By coder1985 in forum Qt Programming
    Replies: 2
    Last Post: 12th January 2008, 14:26
  4. QTcpSocket - How do I know when it is disconnected ?
    By probine in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2006, 21:05
  5. emit a signal
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2006, 11:14

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.