作者:被爱的超萌baby | 来源:互联网 | 2023-07-22 18:28
-------------------------tcp_server.py-------------------------importsocketserverclassMys
-------------------------tcp_server.py-------------------------
importsocketserverclassMyserver(socketserver.BaseRequestHandler):defhandle(self):
self.data= self.request.recv(1024).strip() #self.request相当于conn
print(self.client_address[0], self.data)
self.request.sendall(self.data.upper())if __name__ == '__main__':
ip_port= ("127.0.0.1", 8001)
socketserver.TCPServer.allow_reuse_address=True
server=socketserver.ThreadingTCPServer(ip_port, Myserver)
server.serve_forever()