Don't double post, please.
It's well explained in the example:
In other words, it's the size of the fortune, which is the size of the whole block minus the size of the quint16 in the beginning.At the start of our QByteArray, we reserve space for a 16 bit integer that will contain the total size of the data block we are sending. We continue by streaming in a random fortune. Then we seek back to the beginning of the QByteArray, and overwrite the reserved 16 bit integer value with the total size of the array. By doing this, we provide a way for clients to verify how much data they can expect before reading the whole packet.Qt Code:
out << (quint16)0; out << fortunes.at(qrand() % fortunes.size()); out.device()->seek(0); out << (quint16)(block.size() - sizeof(quint16));To copy to clipboard, switch view to plain text mode





Reply With Quote
Bookmarks