udp协议没有粘包问题
没有建立连接
数据报:每一条数据自带一个报头
import socket client=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) while True: msg=input('>>: ').strip() client.sendto(msg.encode('utf-8'),('127.0.0.1',8082)) data,server_addr=client.recvfrom(1024) print(data)
import socket server=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) server.bind(('127.0.0.1',8082)) while True: data,client_addr=server.recvfrom(1024) print(data) server.sendto(data.upper(),client_addr) server.close()