You need to implement your own protocol on top of the streaming TCP protocol.
Two possible approaches were:
- First send the length of the data to come in fixed length format, then send exactly this amount of bytes.
- Define a delimiter sequence used to terminate a data block having any length. For text data this could be a new-line sequence for example, that is
\r\n
as used by the http protocol.