Hello,

I am adapting networking code from Fortune client and Fortune server examples in Qt 4.6 documentation for my needs, code for reading data looks like this:
Qt Code:
  1. QDataStream in(tcpSocket);
  2. quint16 blockSize;
  3. in.setVersion(QDataStream::Qt_4_0);
  4.  
  5. if (blockSize == 0) {
  6. if (tcpSocket->bytesAvailable() < (int)sizeof(quint16))
  7. return;
  8.  
  9. in >> blockSize;
  10. }
  11.  
  12. if (tcpSocket->bytesAvailable() < blockSize)
  13. return;
  14.  
  15. QString nextFortune;
  16. in >> nextFortune;
To copy to clipboard, switch view to plain text mode 

sending data on the server like this:
Qt Code:
  1. QByteArray block;
  2. QDataStream out(&block, QIODevice::WriteOnly);
  3. out.setVersion(QDataStream::Qt_4_0);
  4. out << (quint16)0;
  5. out << fortunes.at(qrand() % fortunes.size());
  6. out.device()->seek(0);
  7. out << (quint16)(block.size() - sizeof(quint16));
  8. ...
  9. clientConnection->write(block);
To copy to clipboard, switch view to plain text mode 

it's quite simple and elegant,server attaches quint16 number,size of the data at the beginnig of each network message,then client reads it only when all of the data is available. however,it first reads the block size which removes it from the socket's buffer and i would like to just peek at the block size and leave it in the buffer.
My problem is,using QTcpSocket.peek() gives me access to the raw data,not to the serialized quint16 blockSize at the begining of the received data buffer. So,is there any proper way to peek at serialized data from QDataStream? Or is it a good idea to insert block size at the server side as raw data?
I could live without it,but it would somewhat complicate my code.
Thanks in advance for all answers.