套接字的信仰
一切皆文件
昨日作业:
import socket sock=socket.socket() # TCP协议 IP_PORT=("127.0.0.1",8899) sock.bind(IP_PORT) sock.listen(5) while 1: conn,addr=sock.accept() while 1: try: data=conn.recv(1024).decode("utf8") user,pwd=data.strip().split("|") #strip 是为了去掉接受到文件中的空格 #split是以|为分割线,分隔输入进来的字符串分割后形成列表 # 文件操作 flag=False with open("account","r") as f: for line in f: username,password=line.strip().split(":") if username==user and password==pwd: flag=True break if flag: conn.send(b"success") else: conn.send(b"fail") except Exception as e: break服务端