实现代码如下: #udp协议通信import socket,timeclass UdpConnect: def get_udp(self,ip,port,message): #建立udp连接 mysocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) mysocket.connect((ip, port)) #发送数据包并关闭连接 mysocket.send(message.encode('GBK')) mysocket.close()