Multiple calls to send() are merged into one call to recv()
TCP is a streaming protocol. It is not aware at all of any kind of "message" boundaries. It does not add such information dependend on single calls to send()
.
Due to those facts any number of send()
s on the sender side can lead to any number of recv()
s (up to the number of bytes sent) on the receiver side.
To get around this behaviour define and implement an application level protocol to distinguish the different "messages" that had been sent.
One cannot rely on recv()
/send()
receiving/sending as much bytes as those two functions were told to receive/send. It is an essential necessity to check their return value to learn how much bytes those functions actually received/sent and loop around them until all data that was intended to be received/sent had been received/sent.
For examples how this "looping" could be done
- for writing you might like to have look at this answer: https://stackoverflow.com/a/24260280/694576 and
- for reading on this answer: https://stackoverflow.com/a/20149925/694576