What Does Socket Recv Return

The recv() call receives data on a socket with descriptor socket and stores it in a buffer. The recv() call applies only to connected sockets. This call returns the length of the incoming message or data. If a datagram packet is too long to fit in the supplied buffer, datagram sockets discard excess bytes.

What does socket recv return Python?

If no error occurs, recv returns the bytes received. If the connection has been gracefully closed, the return value is an empty byte string. The recv is a blocking method that blocks until it is done, or a timeout is reached or another exception occurs.

What is returned by recv () from the server after it is done sending the HTTP request?

On failure, recv() returns SOCKET_ERROR which (I think) is -1 . Handling HTTP responses correctly requires significant effort. The receiving code needs to examine the returned HTTP headers to determine how to handle the response content. For example, a HTTP response may be chunked or not.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest