文章目录
一、简单实现服务端与多客户端同时交互
服务端:
import socketserver
class Mysever(socketserver.BaseRequestHandler):
def handle(self):
print('服务端启动...')
while True:
conn = self.request
print(self.client_address)
while True:
client_data = conn.recv(1024)
print(str(client_data,'utf8'))
print('waiting writing...')
conn.sendall(bytes(input('>>>'),'utf8'))
conn.closs()
if __name__ == '__main__':
sever = socketserver.ThreadingTCPServer(('127.0.0.1',9999),Mysever)
#TCPServer--->单
#ThreadingTCPServer--->并发
sever.serve_forever()