admin管理员组文章数量:1391964
I need to read the payload of a UDP message transmitted by a server with IP 172.19.66.100
with port 50493
, to another server with IP 239.9.66.100
with port 1000
.
With Wireshark I can read it, but I am not able to when using QUdpSocket.
This is my code, based on the standard Qt example:
#include <QLabel>
#include <QPushButton>
#include <QUdpSocket>
#include <QVBoxLayout>
#include <QNetworkDatagram>
#include "receiver.h"
Receiver::Receiver(QWidget *parent)
: QWidget(parent)
{
statusLabel = new QLabel(tr("Listening for broadcasted messages"));
statusLabel->setWordWrap(true);
auto quitButton = new QPushButton(tr("&Quit"));
//! [0]
udpSocket = new QUdpSocket(this);
udpSocket->bind(QHostAddress("239.9.66.100"), 1000);
//! [0]
//! [1]
connect(udpSocket, &QUdpSocket::readyRead,
this, &Receiver::processPendingDatagrams);
//! [1]
connect(quitButton, &QPushButton::clicked,
this, &Receiver::close);
auto buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
buttonLayout->addWidget(quitButton);
buttonLayout->addStretch(1);
auto mainLayout = new QVBoxLayout;
mainLayout->addWidget(statusLabel);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Broadcast Receiver"));
}
void Receiver::processPendingDatagrams()
{
//! [2]
while (udpSocket->hasPendingDatagrams()) {
QNetworkDatagram datagram = udpSocket->receiveDatagram();
statusLabel->setText(QString(datagram.data().toHex()));
//! [2]
}
}
I guess the problem is in this line:
udpSocket->bind(QHostAddress("239.9.66.100"), 1000);
I tried different solutions but none is really working. The only way I managed to read the message, is by transmitting the message directly to my local IP, instead of the server IP, but it is not what I need.
How should I modify my code?
本文标签: cHow do I read a payload to a different IP with QUdpSocketStack Overflow
版权声明:本文标题:c++ - How do I read a payload to a different IP with QUdpSocket? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744674856a2619048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论