1 import socketserver 2 class FtpServer(socketserver.BaseRequestHandler): 3 def handle(self): 4 print(self.request) #conn 5 print(self.client_address) 6 while True: 7 data=self.request.recv(1024) 8 self.request.send(data.upper()) 9 10 if __name__ == '__main__': 11 s=socketserver.ThreadingTCPServer(('127.0.0.1',8080),FtpServer) 12 s.serve_forever() #链接循环有了
1 from socket import * 2 client=socket(AF_INET,SOCK_STREAM) 3 client.connect(('127.0.0.1',8080)) 4 5 while True: 6 msg=input('>>: ') 7 client.send(msg.encode('utf-8')) 8 9 data=client.recv(1024) 10 print(data)