zoukankan      html  css  js  c++  java
  • Qt 的udpSocket通信

    udpSocket = new QUdpSocket(this);
    QByteArray datagram = "blog.const.net.cn";
    udpSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, 45454);
    udpSocket->bind(QHostAddress("192.168.1.104"), 45454);

    UDP客户端广播
    QUdpSocket *udpsocket1 = new QUdpSocket(this);
    QByteArray datagram = "http://blog.const.net.cn"; udpsocket1->writeDatagram(datagram.data(),datagram.size(), QHostAddress::Broadcast,ui->spinBox->text().toInt());


    UDP客户端发送到指定IP
    QUdpSocket *udpsocket1 = new QUdpSocket(this);
    QByteArray datagram = "http://blog.const.net.cn"; udpsocket1->writeDatagram(datagram.data(),datagram.size(), QHostAddress("192.168.1.104"),ui->spinBox->text().toInt());

    收数据
    connect(udpsocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
    while (udpsocket->hasPendingDatagrams())
    {
    QByteArray datagram;
    datagram.resize(udpsocket->pendingDatagramSize());
    QHostAddress sender;
    quint16 senderPort;
    udpsocket->readDatagram(datagram.data(), datagram.size(), &sender, &senderPort);
    qDebug()<<datagram.data()<<datagram.size()<<senderPort<<sender.toString(); //processTheDatagram(datagram);
    }

  • 相关阅读:
    Dom页面加载
    Redis
    Ubuntu下git的安装与使用
    类Xadmin插件--海豚插件
    Python基础指随笔
    前端必须掌握30个CSS3选择器
    SweetAlert插件示例
    Pylint在项目中的使用
    django Cookie、Session和自定义分页
    django创建超级用户
  • 原文地址:https://www.cnblogs.com/onlycxue/p/2827403.html
Copyright © 2011-2022 走看看