Serialized QByteArray length
I want to send serialized QByteArray (may have arbitrary size) via TCP socket. I have read that signal readyRead() can be emitted even not all data available and user must manually check it by calling bytesAvailable(). But I didn't found how to get array's size on receiver side.
Re: Serialized QByteArray length
Once way would be to send the array size first, and then send the array. That way you know the size of the array on the receiver side.
Re: Serialized QByteArray length
What is minimal size when readyRead signal emitted? Is it guaranteed more than 4 bytes?
Re: Serialized QByteArray length
It could be 1 byte.
If your array will be less than 255 characters then send 1 byte for the length.
If your array will be less than 65535 characters then send 2 bytes for the length and ensure you have 2 bytes before assuming you have the length.
etc.
Re: Serialized QByteArray length
Quote:
Originally Posted by
squidge
It could be 1 byte.
If your array will be less than 255 characters then send 1 byte for the length.
If your array will be less than 65535 characters then send 2 bytes for the length and ensure you have 2 bytes before assuming you have the length.
etc.
Thanks.
I think it will be better to send always 32-bit interger (qint32) and check bytesAvailable >= 4.