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

Stephen Collyer scollyer at netspinner.co.uk
Thu Jul 30 15:03:55 CEST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090730/40fa9022/attachment.html 


More information about the Qt-interest-old mailing list