import socket def main(): client=socket.socket() client.connect(("127.0.0.1",8081)) while True: inputs=input(">>>").strip() client.send(len(inputs).to_bytes(1,byteorder="little",signed=False)) client.send(inputs.encode()) recvs=client.recv(1025) print(recvs.decode(encoding="utf-8")) if __name__=="__main__": main()
import socket def process(conn,address): print("client connect :",conn,address) try: while True: data=conn.recv(1024) if len(data)==0: break else: print(data.decode()) conn.send(data) except ConnectionResetError as e: print(e) def main(): server=socket.socket() server.bind(("127.0.0.1",8081)) server.listen(5) while True: conn,address=server.accept() process(conn,address) if __name__=="__main__": main()