近期Python
作者:互联网
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()
标签:__,socket,Python,近期,client,address,main,conn 来源: https://www.cnblogs.com/leo0362/p/16461655.html