我在使用选择时遇到问题。我只是想知道哪些客户仍然在那里接收数据。有我的代码:
import socket, select
server = socket.socket()
server.bind(('localhost',80))
server.listen(1)
answer = "HTTP/1.1 200 OK\r\n"
answer+= "Content-type: text/plain\r\n"
answer+= "Connection: close\r\n"
body = "test msg"
answer+= "Content-length: %d\r\n\r\n" % len(body)
answer+= body
clients = []
while True:
nextclient,addr = server.accept()
clients.append(nextclient)
clients = select.select([],clients,[],0.0)[1]
for client in clients:
client.send(answer)
每次打开之前打开的所有套接字时,选择发送我,即使连接在另一端关闭,这也会导致 Errno1053 :已建立的连接被主机中的软件中止。
我提前感谢您的帮助。