socket
import socket #创建了一个socket对象 server = socket.socket() #创建一个手机 ip_port = ("192.168.15.30",8004)#创建 大于1024 6 #绑定IP地址和端口 server.bind(ip_port)#插上 #监听IP地址和端口 server.listen()#开机 # print(11111) #等待客户端的连接 conn, addr = server.accept()#等着别人给我打电话阻塞住 conn连接通道 # print(22222) import socket from_client_list = conn.recv(1024) from_client_list = from_client_list.decode("utf-8") print(from_client_list) li = from_client_list.split("_") print(li) server_username = "张雷" #正确的用户名 server_password = "123" #正确的密码 if li[0] == server_username and li[-1] == server_password: print("登录成功") conn.send("登录成功".encode("utf-8")) else: conn.send("用户或密码错误".encode("utf-8")) print("用户或密码错误") #关闭连接 conn.close() server.close()
import socket client = socket.socket() server_ip_port = ("192.168.15.30",8004) #连接服务端 client.connect(server_ip_port) #发消息 username = input("请输入用户名:").strip() password = input("请输入密码:").strip() cc = username + "_" + password client.send(cc.encode("utf-8")) client_client_list = client.recv(1024) client_client_list = client_client_list.decode("utf-8") print(client_client_list) client.close()