[Qt-interest] set connection timeout on QTcpSocket/AbstractSocket

Donal O'Connor donaloconnor at gmail.com
Thu Jul 30 15:40:56 CEST 2009


Hi,

Sounded like a good idea but...

I set it a single shot of 1000ms before I attempted to call connect.
Whole program locks up then for 30 seconds and I get to timeout slot called
then after 30 seconds rather than 1.

Everything is fine once I can contact the server, but when it not
contactable, this is what happens.


I'm not sure if it is anything to do with threads, should I run the
QTCPSocket connection in another thread to prevent blocking? Or maybe I
should be doing that in the first place.

On Thu, Jul 30, 2009 at 2:03 PM, Stephen Collyer
<scollyer at netspinner.co.uk>wrote:

> 2009/7/30 Donal O'Connor <donaloconnor at gmail.com>
>
>> Hi,
>>
>>
>> I've searched the docs everywhere but I cannot see if it is possible to
>> set a timeout value when connecting to a host.
>>
>> I'm using connectToHost(server,port). This seems to hang my application on
>> Windows CE until it times out about 10 - 30 seconds later when I receive the
>> error via the
>> error() signal emitted.
>>
>> Is there a way to set a timeout value so I don't have to wait this long
>> before showing the error to the user?
>>
>
> The connection timeout in general is determined by the TCP stack of
> the o/s that you're using, and you probably won't ever be able to
> increase this (though you don't want to here, anyway).
>
> If you want to decrease it, you could try something based on a QTimer
> running in single shot mode. When the timer emits the timeout() signal,
> look at the socket state to see if it's connected, and if not close() it,
> or
> destroy it or whatever you need to do. I think it would be straightforward
> to wrap this up in a subclass of QTcpSocket.
>
> --
> Stephen Collyer
>
> _______________________________________________
> 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/20090730/095fc6af/attachment.html 


More information about the Qt-interest-old mailing list