I have this problem. If the sender sends messages consecutively, like message 1 and message 2 and at the receiver attempt is made to read each message individually, then the receiver gets the both messages as the message 1. Is there any built-in mechanism such that the receiver delivers messages separately or do I have to do that myself. If so then I guess I have to present the length of the message at the header or set each message to be of the same size.


Or you could use UDP instead of TCP.
TCP doesn't guarantee packet data size only that it will get delivered in order...like you said if you want to extract individual messages then you'll have to figure out an application protocol to handle it..