Shuzheng
Shuzheng

Reputation: 14038

Where is it stated that the socket.recv() call returns the empty bytes object if the other end of the stream has called socket.close()?

I've been skimming the Python documentation, but can't seem to find specific details like the above. Where are such details listed?

Upvotes: 1

Views: 973

Answers (1)

Anand S Kumar
Anand S Kumar

Reputation: 91009

Since you want the documentation, the below is the closest thing to documentation I could get.

From Python documentation - -

The Python interface is a straightforward transliteration of the Unix system call and library interface for sockets

And from Unix documentation for recv , under the section Return value -

When a stream socket peer has performed an orderly shutdown, the return value will be 0 (the traditional "end-of-file" return).

And when you convert the 0 to a bytes object, you get an empty bytes object. Example -

>>> bytes(0)
b''

Upvotes: 2

Related Questions