I assume that you are using send() and recv() to communicate with the client and server.
So send() will return the number of bytes that were sent. This is not necessarily equal to the number of bytes you sent that you wanted , so you need to realize this and send the rest.
Now recv() returns the number of bytes read into the buffer. Therefore, if recv returns 0, then the server probably closed the connection.
source share