标签:bin add not __name__ erro nic mmu set utf-8
server
from socket import * from threading import Thread def communicate(conn): while True: try: data = conn.recv(1024) if not data: break conn.send(data.upper()) except ConnectionResetError: break conn.close() def servers(ip,port): server = socket(AF_INET, SOCK_STREAM) server.bind((ip, port)) server.listen(5) while True: conn,addr=server.accept() print(conn,addr) t=Thread(target=communicate,args=(conn,)) t.start() server.close() if __name__=="__main__": servers("127.0.0.1",8081)
client
from socket import * client=socket(AF_INET,SOCK_STREAM) client.connect(("127.0.0.1",8081)) while True: msg=input(">>:").strip() if not msg:break client.send(msg.encode("utf-8")) data=client.recv(1024) print(data.decode("utf-8")) client.close()
标签:bin add not __name__ erro nic mmu set utf-8
原文地址:https://www.cnblogs.com/yaya625202/p/9048101.html