Hi all
I have two network applications, something like client and server.
On the server side I write data to socket which is in QByteArray.
qint64 size = socket->write(array);
qDebug() << "written" << size;
qint64 size = socket->write(array);
qDebug() << "written" << size;
To copy to clipboard, switch view to plain text mode
On the client side in slot which is connected to readyRead signal I first read quint32 which is size of data and then I read data to QByteArray.
quint32 size;
socketStream >> size;
qDebug() << "size" << size;
qDebug() << "socketAvailable" << quint32(socket->bytesAvailable());
if (quint32(socket->bytesAvailable()) < size)
return;
QDataStream socketStream(socket);
quint32 size;
socketStream >> size;
qDebug() << "size" << size;
qDebug() << "socketAvailable" << quint32(socket->bytesAvailable());
if (quint32(socket->bytesAvailable()) < size)
return;
QByteArray array = socket->read(size);
To copy to clipboard, switch view to plain text mode
So qDebug() on server side give me
warning: written 17980
warning: written 224
warning: written 135176
warning: written 17980
warning: written 224
warning: written 135176
To copy to clipboard, switch view to plain text mode
but on teh client side
warning: size 17976
warning: socketAvailable 17976
warning: size 220
warning: socketAvailable 220
warning: size 135172
warning: socketAvailable 98300
warning: size 17976
warning: socketAvailable 17976
warning: size 220
warning: socketAvailable 220
warning: size 135172
warning: socketAvailable 98300
To copy to clipboard, switch view to plain text mode
First four warnings are correct becouse I read size which is 4 bytes so it is smaller but the last two do not match. Every time I write to socket more then 98304 bytes it doesnt let me to read them all and I do not know why. In the second calling of client slot when is readyRead emit again there are all data available but I cant read it exactly becouse I have already read their size before. How can I solve this problem? Thanks.
Bookmarks