服务器:
import socketserver class Myserver(socketserver.BaseRequestHandler): def handle(self): while 1: from_client = self.request.recv(1024) #self.request相当于conn print(from_client.decode('utf-8')) self.request.send('好'.encode('utf-8')) pass if __name__ == '__main__': server = socketserver.ThreadingTCPServer(('121.195.167.34',8002),Myserver) server.serve_forever()
可以开启多个客户端同时连接