[Qt-interest] Correct way of reading large data with QLocalSocket

Info info at misafe.com
Thu Sep 24 19:13:25 CEST 2009


Hi,

I'm using QLocalSocket/QLocalServer to read around 200kb of data, on  
the server-side there is an event loop which sends data like this:

QByteArray headerblock;
QDataStream header(&headerblock, QIODevice::WriteOnly);
header << (int)(response.length() + sizeof(int));
sock->write(headerblock);
sock->write(response);
sock->waitForBytesWritten();
sock->close();

On the client side, there is no event loop but data is read like this:

sock.waitForReadyRead()
QByteArray input(sock.read(sizeof(int)));
QDataStream in(&input, QIODevice::ReadOnly);
int length, read = 0;
in >> length;
while( input.length() < length )
{
	input.append(sock.read(sock.bytesAvailable()));
	qDebug() << "Read"<<input.length();
	if( !sock.waitForReadyRead() )
		return 0;
}

The return value of the sock->write() call is the correct number of  
bytes when I check it but on the client side, I get an maximum of 4096  
bytes. Is there a better way to do this?

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090924/faa8024c/attachment.html 


More information about the Qt-interest-old mailing list