QT--程序收不到组播数据
侧边栏壁纸
  • 累计撰写 25 篇文章
  • 累计收到 0 条评论

QT--程序收不到组播数据

247
247
2023-05-01 / 0 评论 / 88 阅读 / 正在检测是否收录...

主要需要设置组播网卡

 
QString strName = ui->comboBox_network->currentData().toString();
    interface =  QNetworkInterface::interfaceFromName(strName);   // 根据选择名称获取网卡
 
QByteArray data;
tftudpsocket = new QUdpSocket();
        tftsendaddres.setAddress("239.1.1.15");
        tftudpsocket->bind(QHostAddress(ip), 6002, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
        //加入组播组
        tftudpsocket->setSocketOption(QAbstractSocket::MulticastLoopbackOption, 0);
        //设置组播网卡
        tftudpsocket->setMulticastInterface(interface);
 
        tftudpsocket->joinMulticastGroup(QHostAddress(tftsendaddres), interface);
        connect(tftudpsocket, SIGNAL(readyRead()), this, SLOT(read_tftdata()));
        //发送一个空数据出去
        tftudpsocket->writeDatagram(data, QHostAddress(tftsendaddres), 6002);
0

评论 (0)

取消