import select
import socket
loop = select.epoll()
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('0.0.0.0', 8000))
sock.listen(1000)
conn, src = sock.accept()
loop.register(conn.fileno(), select.POLLIN)
while True:
loop.poll()
data = conn.recv(1024)
if not data:
print('receive nothing')
我上面有这个脚本,(我猜)它永远不会打印"receive nothing"
,因为poll()
注册的select.POLLIN
只有在确实要从套接字中读取内容时才会返回。但是,当我
> nc localhost 8000
test
脚本不断喷出"receive nothing"
。