listen挂的是链接请求,半链接池,不是完整的链接
from socket import *
udp_server=socket(AF_INET,SOCK_DGRAM) #数据报
udp没有链接,每次发包都要指定ip端口
from socket import * ip_port=('192.168.1.6',8002) buffer_size=1024 udp_server=socket(AF_INET,SOCK_DGRAM) udp_server.bind(ip_port) while True: data,addr=udp_server.recvfrom(buffer_size) print(data) udp_server.sendto(data.upper(),addr)
from socket import * ip_port=('192.168.1.6',8002) buffer_size=1024 udp_client=socket(AF_INET,SOCK_DGRAM) while True: msg=input('>>:') udp_client.sendto(msg.encode('utf-8'),ip_port) data=udp_client.recvfrom(buffer_size) print(data)
来源:https://www.cnblogs.com/jintian/p/10970823.html