标签:nbsp connect add serve lis 技术分享 listen phone color
server
import socket phone=socket.socket(socket.AF_INET,socket.SOCK_STREAM) phone.bind((‘127.0.0.1‘,8080)) phone.listen(5) conn,client_addr=phone.accept() print(client_addr) #通信循环 while True: data=conn.recv(1024) print("Client data:",data) conn.send(data.upper()) conn.close()
client
import socket client=socket.socket(socket.AF_INET,socket.SOCK_STREAM) client.connect((‘127.0.0.1‘,8080)) #通信循环 while True: msg=input(‘>> ‘).strip() client.send(msg.encode(‘utf-8‘)) data=client.recv(1024) print(data) #关闭连接 client.close()
标签:nbsp connect add serve lis 技术分享 listen phone color
原文地址:https://www.cnblogs.com/yaya625202/p/8947518.html