Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.8.5
-
None
-
Windows 7 SP1 x64
Qt 4.8.5 mingw
mingw-gcc 4.4.0
Description
Hi.
I have a server which sends 4kb data approximately every 2 second. I'm trying to read data with QTCPSocket. Here is the example code.
QHostAddress addr(m_ip);
m_socket = new QTcpSocket(this);
m_socket->connectToHost(addr, 8899);
m_socket->setReadBufferSize(4096);
while(m_socket->waitForReadyRead()) {
qDebug() << "Avaliable " << m_socket->bytesAvailable();
m_socket->read(m_buffer, 4096);
}
the debug output is following
Avaliable 2920
Avaliable 1176
Avaliable 1460
Avaliable 1460
Avaliable 1176
this is output when program is run about 5 seconds. The problem is that first two lines are printed at once and the other are printed 2 seconds later. As you see
2920 + 1176 = 4096
1460 + 1460 + 1176 = 4096
and the data is split to 2 or 3 parts. Same is true when using QTCPSocket signal readyRead(). The corresponding slot is called 2 or 3 times.
To find out if this is Qt problem, I've written a small WinSocks2 example application which is attached. It outputs received bytes number as expected
Received: 4096
Received: 4096
Received: 4096
with about 2 second intervals.
The only difference is, that winsock example is compiled with gcc 4.8.1 and the QTCPSocket example was compiled with gcc 4.4.0