Recv Function
Int Recv (socket S, char far * Buf, int Len, int flags );
Both the client and server applications use the Recv function to receive data from the other end of the TCP connection.
The first parameter of this function specifies the receiver socket descriptor;
The second parameter specifies a buffer that is used to store the data received by the Recv function;
The third parameter specifies the length of the Buf;
The fourth parameter is usually set to 0.
This only describes the execution process of the Recv function that synchronizes the socket. When the application calls the Recv function, the Recv waits for the data in the s sending buffer to be transmitted by the Protocol. If the Protocol encounters a network error when sending data in the s sending buffer, then the Recv function returns socket_error. If no data is in the sending buffer of s or the data is successfully sent by the protocol, the Recv checks the receiving buffer of socket s first, if there is no data in the s receiving buffer or the Protocol is receiving data, the Recv waits until the Protocol receives the data. When the Protocol receives the data, the Recv function copies the data in the s receiving buffer to the Buf (note that the data received by the protocol may be larger than the length of the Buf, in this case, you need to call the Recv function several times to copy the data in the s receiving buffer. The Recv function only copies data, and the real data reception is completed by the Protocol). The Recv function returns the actual number of bytes of the copy. If a Recv error occurs during copy, socket_error is returned. If the Recv function is interrupted while waiting for the Protocol to receive data, 0 is returned.