import socket sk = socket.socket() sk.bind(("127.0.0.1", 9030)) sk.listen(5) sock, addr = sk.accept() while True: data = sock.recv(1024).decode("utf-8") print(data) content = input(">>>>") sock.send(bytes(content, encoding="utf-8")) if data == "bye": break sock.close() sk.close()
import socket sk = socket.socket() sk.connect(("127.0.0.1", 9030)) while True: content = input(">>>>>>") sk.send(bytes(content, encoding="utf-8")) data = sk.recv(1024).decode("utf-8") print(data) if data == "bye": break sk.close()
原文:https://www.cnblogs.com/blogsupermouse/p/10838016.html