The reason can be that you haven't checked out the documentation of these two functions and you probably don't check their return value: send()
]. Always check the return value for errors, and never assume that they sent the whole buffer. If they sent/received only part of the data then increase the pointer into your buffer and issue another
call to send/receive the remaining data.