select服务端代码
from socket import *
from select import *
s = socket(AF_INET, SOCK_STREAM)
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
s.bind(('localhost', 8888))
s.listen(4)
rl = [s]
while True:
rs, ws, xs = select(rl,rl,rl)
print('yyyyy')
c,addr = rs[0].accept()
print('xxxxx')
# rl.append(c)
# print(c.recv(1024))
s.send()在select中所引起的IO就绪态是属于连接套接字的,而不再是listen套接字的IO触发
所以在没有将连接套接字放入监测列表的情况下,select不会知道客户端要send()
打印结果
yyyyy
xxxxx
打印结果
1
2
客户端代码
from socket import *
s = socket()
s.connect(('localhost', 8888))
print(1)
s.send(b'qweqwe')
print(2)