利用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()
STRIVE FOR PROGRESS,NOT FOR PERFECTION