我试图在windows下运行以下python服务器:"""
An echo server that uses select to handle multiple clients at a time.
Entering any line of input at the terminal will exit the server.
"""
import select
import socket
import sys
host = ''
port = 50000
backlog = 5
size = 1024
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((host,port))
server.listen(backlog)
input = [server,sys.stdin]
running = 1
while running:
inputready,outputready,exceptready = select.select(input,[],[])
for s in inputready:
if s == server:
# handle the server socket
client, address = server.accept()
input.append(client)
elif s == sys.stdin:
# handle standard input
junk = sys.stdin.readline()
running = 0
else:
# handle all other sockets
data = s.recv(size)
if data:
s.send(data)
else:
s.close()
input.remove(s)
server.close()
我收到错误消息(10038,“试图对非套接字的内容执行操作”)。这可能与python文档中的the remark有关,“Windows上的文件对象是不可接受的,但是sockets是可以接受的。在Windows上,底层的select()函数是由WinSock库提供的,它不处理不是来自WinSock的文件描述符。在互联网上有很多关于这个话题的帖子,但它们要么对我来说太技术化了,要么根本不清楚。所以我的问题是:python中的select()语句是否可以在windows下使用?请添加一个小例子或修改我的代码以上。谢谢!