利用sockserver快速实现TCP服务器
作者:互联网
from socket import socket import socketserver import sys class MyTCPRequestHandler(socketserver.StreamRequestHandler): def handle(self) -> None: while True: print('[-] Got connection from %s: %s' % (self.client_address[0],self.client_address[1])) command = input(' %s ~ ' % self.client_address[0]) self.request.send(command.encode('utf-8')) if command.strip() == 'q': break recv_result = self.request.recv(1024) print(recv_result.decode('utf-8').strip()) server =socketserver.TCPServer(('0.0.0.0',6666),MyTCPRequestHandler) server.serve_forever()
标签:socketserver,import,self,TCP,client,address,服务器,sockserver,recv 来源: https://www.cnblogs.com/jason-huawen/p/16383527.html