标签:-- 字母数 end else res 返回值 收信 address serve
server类 import socket sk = socket.socket() #创建socket #添加地址bind绑定 address = ("127.0.0.1",9595) sk.bind(address) #支持多少人 sk.listen(2) #接收客户端信息 conn,addr = sk.accept() while True: cr = conn.recv(1024) if cr: print(cr,"--------------") #判断客户端停止后返回值 print(str(cr,"utf8")) # print(str(cr)) #这个不能接收中文,只能接收字母数字 #发送信息 inp = input("服务的输入:") if inp == "88": break else: conn.send(bytes(inp,"utf8")) else: break
client类 import socket sk = socket.socket() #创建socket对象 #连接服务端 address = ("127.0.0.1",9595) sk.connect(address) #发送信息到服务端 while True: inp = input("这是客户端:") if inp == "88": break else: sk.send(bytes(inp,"utf8")) #接收信息 sr = sk.recv(1024) print("-----------",sr) if sr: print(str(sr, "utf8")) else: break
标签:-- 字母数 end else res 返回值 收信 address serve
原文地址:https://www.cnblogs.com/TKOPython/p/12394844.html