标签:socket threading port mys res and close print 用户
import socketserver #创建类并继承基本类 class Myserver(socketserver.BaseRequestHandler): #继承handle类 def handle(self): while True: conn = self.request print(conn) while True: data = conn.recv(1024) print(str(data,"utf8")) inp = input("输入:") conn.sendall(bytes(inp,"utf8")) conn.close() serv = socketserver.ThreadingTCPServer(("127.0.0.1",6665),Myserver) serv.serve_forever()
import socket sk = socket.socket() address = ("127.0.0.1",6665) sk.connect(address) while True: inp = input("客户端输入:") sk.sendall(bytes(inp,"utf8")) ee = sk.recv(1024) print(str(ee,"utf8"))
标签:socket threading port mys res and close print 用户
原文地址:https://www.cnblogs.com/TKOPython/p/12428035.html