You are falsely assuming that if you send two blocks of data then the receiver will receive the data as two blocks containing one message each. TCP has no concept of messages, it treats data as an opaque stream of octets. The receiver can receive all messages in one segment or each message can be divided into several segments. You should buffer all incoming data and analyze the buffer looking for message boundaries based on the application protocol you implemented on the sender side.