A common mistake beginners make is assuming that any data passed into send() can be read by recv() on the other end in the same amount. In reality, sending data is similar to writing and reading from a file. If we write 10 bytes to a file, followed by another 10 bytes, then the file has 20 bytes of data. If the file is to be read later, we could read 5 bytes and 15 bytes, or we could read all 20 bytes at once, and so on. In any case, we have no way of knowing that the file was written in two 10 byte chunks.
Using send() and recv() works the same way. If you send() 20 bytes, it's not possible to tell how many recv() calls these bytes are partitioned into. It is possible that one call to recv() could return all 20 bytes, but it is also possible that a first call to recv() returns 16 bytes and that a second call to recv() is needed to...