[Qt-interest] QTcpServer timeout ?

BRM bm_witness at yahoo.com
Wed Jul 21 00:43:26 CEST 2010


I believe you only have to do it on one side. QTcpServer won't have kind of 
support for this - nor should it; the support should go into 
QTcpSocket/QAbstractSocket if Nokia/Qt decides to do so.
AFAIK, it really doesn't matter which side sets up the Keep Alive; however, I 
would guess that most probably do so on the client-side.

Ben


>
>From: David Boosalis <david.boosalis at gmail.com>
>To: BRM <bm_witness at yahoo.com>
>Cc: QtInterest <qt-interest at trolltech.com>; aschmidt at dekaresearch.com
>Sent: Tue, July 20, 2010 5:47:03 PM
>Subject: Re: [Qt-interest] QTcpServer timeout ?
>
>BRM, Atlant.
>
>Thanks for your insight and feedback.  I read up on KeepAlive switch and it 
>basically does the polling for you without notifying your application as it is 
>doing so.  I think QTcpServer out to have methods for doing this.  But I was 
>able to do it with the following lines.
>
>
> int sockID = myQtSocket->socketDescriptor();
>  flag = 1;
>  ret = setsockopt( sockID, SOL_SOCKET, SO_KEEPALIVE, (char *)&flag, 
>sizeof(flag));
>
>
>One final question regarding KeepAlive. Should it be done on the server side or 
>client side, or does it not matter ?
>  
>
>
>
>On Tue, Jul 20, 2010 at 2:23 PM, BRM <bm_witness at yahoo.com> wrote:
>
>There is also another solution, though you may have to fall-back to some 
>platform specific code to enable it.
>>
>>Both Windows and Linux do have system level timers on the sockets. However, you 
>>can set a KEEP_ALIVE socket option.
>>While this can be specified on the socket creation (e.g. open()), it can also be 
>>set via the socket options (setsockopt() for Linux).
>>The KEEP_ALIVE option basically makes the operating system send the messages at 
>>the TCP protocol layer (per RFC 1122);
>>thus you don't have to generate or parse more messages or have to maintain a 
>>timer yourself to send them.
>>
>>http://en.wikipedia.org/wiki/Keepalive#TCP_Keepalive
>>http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html
>>http://msdn.microsoft.com/en-us/library/ms819735.aspx
>>
>>I could not quickly spot a way to get Qt to do this for you.
>>
>>HTH,
>>
>>Ben
>>
>>
>>>
>>>From: Atlant Schmidt <aschmidt at dekaresearch.com>
>>>To: David Boosalis <david.boosalis at gmail.com>; QtInterest 
>>><qt-interest at trolltech.com>
>>>Sent: Tue, July 20, 2010 4:01:13 PM
>>>Subject: Re: [Qt-interest] QTcpServer timeout ?
>>>
>>>
>>>
>>>David:
>>> 
>>>  It’s quite common for TCP connections of all sorts to have an inactivity 
>>>timer.
>>>  This is especially true if your session connects through a firewall or a 
>>>“public”
>>>  medium.
>>> 
>>>  Because you often can’t affect the settings of the various inactivity 
timers
>>>  you may encounter along the way, the usual solution is, as you surmised,
>>>  the use of keep-alive messages. I’m thinking that every five minutes is
>>>  too long, but that will depend on your particular circumstances.
>>> 
>>>                                    Atlant
>>> 
>>>
________________________________
 
>>>From:qt-interest -bounces at trolltech.com [mailto: qt-interest 
>>>-bounces at trolltech.com] On Behalf Of David Boosalis
>>>Sent: Tuesday, July 20, 2010 3:51 PM
>>>To: QtInterest
>>>Subject: [Qt-interest] QTcpServer timeout ?
>>> 
>>>I have Qt Client applications establishing  connections to server apps based 
>>>using QtTcpServer(s).  The sockets that send data quite often  have no problem 
>>>staying connected all day.  However the sockets that send notices maybe one 
>>>every two hours or perhaps just once a day tend to die. I never see a 
>>>disconnect, but the socket just seems to go to sleep as data fails to arrive to 
>>>the server.  I  was wondering if a time out occurring due to  the lack of 
>>>activity going across the socket.  I looked at the QTcpServer class for a method 
>>>that might turn off such a timer but did not see any.  Perhaps this behaviour 
>>>goes beneath QT and into the  Linux Tcp  Server design. If so is there a low 
>>>level call I can make on the socket ID to keep the connection always alive.  I 
>>>am thinking about sending a ping every 5 minutes on these sockets.  
>>>
>>>
>>>Any advise on how best to fix this time out is very much appreciated.
>>>
>>>-David
>>>
>>>
>>>
>>>Click here to report this email as spam.
>>>________________________________
 This e-mail and the information, including any attachments, it contains are 
intended to be a confidential communication only to the person or entity to whom 
it is addressed and may contain information that is privileged.  If the reader 
of this message is not the intended recipient, you are hereby notified that any 
dissemination, distribution or copying of this communication is strictly 
prohibited. If you have received this communication in error, please immediately 
notify the  sender and destroy the original message.
>>>
>>>Thank you.
>>>
>>>Please consider the environment before printing this email.
>>> 
>>_______________________________________________
>>Qt-interest mailing list
>>Qt-interest at trolltech.com
>>http://lists.trolltech.com/mailman/listinfo/qt-interest
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100720/e5a58a01/attachment.html 


More information about the Qt-interest-old mailing list