Results 1 to 6 of 6

Thread: Does QSslSocket disconnect after a period of idle time?

  1. #1
    Join Date
    Apr 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Does QSslSocket disconnect after a period of idle time?

    Hi All,

    after a client connects to a server, if nothing is sent between them do the sockets stay connected indefinitely?
    In other words do QSslSockets or the wrapped native sockets have a build in idle timeout whereby if nothing is sent or received the sockets disconnect?

    If sockets do auto disconnect after a period of idle time, how long is this time?
    and if sockets do not auto disconnect after a period of idle time what is the role of the option:
    Qt Code:
    1. QAbstractSocket::KeepAliveOption
    To copy to clipboard, switch view to plain text mode 

    Many Thanks
    _andrea

  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: Does QSslSocket disconnect after a period of idle time?

    Quote Originally Posted by scieck View Post
    after a client connects to a server, if nothing is sent between them do the sockets stay connected indefinitely?
    It solely depends on the system policy of the two ends of the connection. Since there is no way to determine whether we're not receiving data because the other end doesn't have anything to say to us or it is long gone, systems usually assume the tcp connection is broken after some time (e.g. 15 minutes) of silence. Thus tcp stacks implement something called keep-alive to notify the other end they are still there.
    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. #3
    Join Date
    Apr 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Does QSslSocket disconnect after a period of idle time?

    Quote Originally Posted by wysota View Post
    ...Since there is no way to determine whether we're not receiving data because the other end doesn't have anything to say to us or it is long gone, ...
    Thank you wysota,

    i don't understand something, when i kill the client, even without proper shutdown, the server immedialty emits the "QAbstractSocket::RemoteHostClosedError" error.
    Should we not rely on this error been emitted in all cases ? so in some cases, it could be that the client is long gone and the socket on the server side does not know?

  4. #4
    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: Does QSslSocket disconnect after a period of idle time?

    Quote Originally Posted by scieck View Post
    i don't understand something, when i kill the client, even without proper shutdown, the server immedialty emits the "QAbstractSocket::RemoteHostClosedError" error.
    Not always. Pull the network cable out of your router and see if the remote server is notified about it. Or start dropping packets using your firewall software, the server will not have the slightest clue the connection was severed. Or just pull the power plug of one of the machines that are part of the network route from the socket. Or just satitate your link or start causing collisions to build up network congestion.

    Should we not rely on this error been emitted in all cases ?
    No, certainly not. Never rely on an external autonomous system (that is one you have no control over). "Trust no-one" as Agent Mulder would say

    it could be that the client is long gone and the socket on the server side does not know?
    Yes, of course.
    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.


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

    scieck (19th April 2011)

  6. #5
    Join Date
    Apr 2011
    Posts
    14
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Does QSslSocket disconnect after a period of idle time?

    If the QAbstractSocket::KeepAliveOption is set on both peers, if one of the two tcp sockets does not receive a keep-alive packet back in time is this triggered up the Qt level ?
    so in other words by setting the keep-alive option can we findout if the other peer is still there or gone ? and can/should we trust keep-alive?

    thanks again
    _andrea

  7. #6
    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: Does QSslSocket disconnect after a period of idle time?

    Quote Originally Posted by scieck View Post
    If the QAbstractSocket::KeepAliveOption is set on both peers, if one of the two tcp sockets does not receive a keep-alive packet back in time is this triggered up the Qt level ?
    As already said, this is implemented by the operating system.

    so in other words by setting the keep-alive option can we findout if the other peer is still there or gone ? and can/should we trust keep-alive?
    Trust no-one. How can you be sure you're not talking to some alien implementation of the client? In networking you cannot dump any decision on your peer if you can't trust it. You have to be autonomous in your decisions. If you decide you need to receive some heart-beat from the client every 5 minutes and you don't receive it as expected then close the connection yourself without waiting for the tcp/ip stack to do it for you. And first of all understand how underlying protocols (at least tcp and ip) work, what they guarantee and what they don't guarantee.
    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. The following user says thank you to wysota for this useful post:

    scieck (19th April 2011)

Similar Threads

  1. Qt Idle time calculation for symbian
    By winifredrayen in forum Qt Programming
    Replies: 3
    Last Post: 10th December 2010, 13:43
  2. Qt - idle time calculation for symbian mobile
    By winifredrayen in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 10th December 2010, 12:53
  3. display selected period
    By nico.23 in forum Newbie
    Replies: 1
    Last Post: 29th May 2009, 11:37
  4. how do I get the idle time in qt2
    By pencilren in forum Qt Programming
    Replies: 1
    Last Post: 17th September 2007, 04:19
  5. drawing points on canvas after a time period
    By quickNitin in forum Qt Programming
    Replies: 3
    Last Post: 12th May 2006, 14:12

Tags for this Thread

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.