python - 如果流的另一端调用了socket.close(),则在哪里声明socket.recv()调用返回空字节对象?

标签 python sockets

我一直在浏览the Python documentation,但是似乎找不到像上面这样的具体细节。这些详细信息在哪里列出?

最佳答案

由于您需要文档,因此以下内容是我可以获得的最接近的文档。

Python documentation --

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



Unix documentation for recv中,在“返回值”部分下-

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



当您将0转换为字节对象时,将得到一个空字节对象。例子 -
>>> bytes(0)
b''

关于python - 如果流的另一端调用了socket.close(),则在哪里声明socket.recv()调用返回空字节对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31835680/

相关文章:

python - 相当于 Python 中 R 的 sub 和 paste(字符串和数字的连接)

python - "TypeError: can' t 将序列乘以 'tuple' 类型的非整数是什么意思?

python - Pymysql无法导入python3

php stream_get_contents 在流的末尾挂起

python - 为什么这些列表相同?

python - 安装 fastcluster 库时遇到问题,numpy 包含错误

java - 条件 "a server is up"的构成是什么

multithreading - Clojure 多线程输出流

c - 未在服务器端客户端-服务器 TCP 上接收单独的值

python - 让 python tcp 服务器在发送后发送和接收消息?