标签:while strip() 协议 recv bind ndt 数据报 enc soc
import socket
server=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) # 数据报协议=》udp协议
server.bind((‘127.0.0.1‘,8081))
while True:
data,client_addr=server.recvfrom(1024)
server.sendto(data.upper(),client_addr)
server.close()
import socket
client=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) # 流式协议=》tcp协议
while True:
msg=input(‘>>>: ‘).strip()
client.sendto(msg.encode(‘utf-8‘),(‘127.0.0.1‘,8081))
res=client.recvfrom(1024)
print(res)
client.close()
标签:while strip() 协议 recv bind ndt 数据报 enc soc
原文地址:https://www.cnblogs.com/h1227/p/12740412.html