View Full Version : Big buffer over TCP Socket

13th November 2013, 20:04
Hi i am making stream from mobile to PC. In device i use Java app which send a byte array (of a Opencv Mat object) and then it say the array over TCP and on PC i have an Qt app which receive socket and then just show lenght of received data. Data's lenght should be 25 344 but in Qt app:

void Server::readyRead()
QByteArray byte = socket->readAll();
qDebug() << byte.size();

i get 18 lines: On 17 lines is 1448 and on one is 728
when i count it its 25 344 but why it send it like that. From java i send only one message but in Qt it looks like i sent 18 messages
why? Is it the big size of message?

14th November 2013, 06:52
With TCP there is no concept of "messages", just a stream of bytes. The fact that in Java you receive the data in one go is purely incidental, you might as well receive it in 25344 parts. It is your responsibility to detect the end of "message", assemble the data and make use of it.

14th November 2013, 18:51
So if i understand there is no other option just add something with which i will detect the end of stream. Ok thanks for response :)

14th November 2013, 21:49
Typically sending a 4 or 8 byte packet size first, buffering bytes (in a QByteArray or on disk) until that number has been reached, processing the packet, and removing the packet from the buffer leaving any extra bytes in the buffer.

15th November 2013, 15:26
OK thank you very much this is what i needed to know :)