我在使用select時遇到了問題。我只是想知道哪些客戶端仍然在那裏接收數據。這裏是我的代碼:這個基本的Python選擇在Windows上有什麼問題?
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:一個etablished連接是通過在軟件放棄了你主機。
我事先感謝您的幫助。
這不是錯誤的原因。從1到5的積壓和select的不同超時有同樣的問題。無論如何,我不想在那裏有一個街區,我只想知道哪些客戶已經準備好寫作了。 – user1144442