[Interest] Odd behavior with QTcpSocket::waitForReadyRead()

Jason H jhihn at gmx.com
Tue Dec 20 07:31:53 CET 2016


> int msecs = timeout * 1000000

I'm pretty sure that's the conversion for usec, not msec.

Note that in most cases there is a hard-coded 75 second timeout TCP read timeout from the early days of the internet. And anything over 60 is likely to to dropped by firewalls.

You shouldn't be using waitFor*(). Qt uses async sockets, so just set up a readyRead() handler, and keep track of time of last reception, combine it with a QTimer and implement your own timeout. 

> Sent: Monday, December 19, 2016 at 6:38 PM
> From: "Bob Hood" <bhood2 at comcast.net>
> To: "interest at qt-project.org" <interest at qt-project.org>
> Subject: [Interest] Odd behavior with QTcpSocket::waitForReadyRead()
>
> I'm porting a TCP/IP client from wxWdigets to Qt.  I've tried this under both 
> 5.4.2 and 5.6.2.
> 
> I have a user-configured timeout value for network reads.  The default is 300 
> seconds (5 minutes).  I am feeding that to QTcpSocket::waitForReadyRead(), and 
> it's basically ignoring--worse, it's generating an error.  It doesn't seem to 
> matter if it's 300,000 msecs or 3,000,000 msecs, I get "Network operation 
> timed out" (5) returned from it.
> 
>          int msecs = timeout * 1000000;
>          if(!socket.waitForReadyRead(msecs))
>          {
>              QString msg = QString(tr("An error occurred while receiving data 
> from the server: \"%1\" (%2).")).arg(socket.errorString()).arg(socket.error());
>              ...
> 
> This causes the communications to fail, even though the action takes place 
> pretty much instantly, because I'm running the server on the same machine for 
> testing/debugging.  If I tell QTcpSocket::waitForReadyRead() to wait forever:
> 
>          if(!socket.waitForReadyRead(-1))
> 
> everything runs smoothly.
> 
> I've done nothing with the QTcpSocket instance in terms of configuration.  I 
> just create it, and then start the ball rolling with a call to 
> connectToHost().  Have I not configured some Qt5-thing correctly?
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> 



More information about the Interest mailing list