QUDPSocket failing to communicate with any other environment
-
Hello,
I'm having trouble with using QUDPSockets to send or receive packets from outside of the Qt environment.
I have all my firewalls disabled for this problem.Here is the Sender Code in Qt:
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); MyUDP client; client.sayHello(); return a.exec(); } MyUDP::MyUDP(QObject *parent) : QObject(parent) { socket = new QUdpSocket(this); QHostAddress addr ("127.0.0.1"); socket->bind(addr, 55555); } void MyUDP::sayHello() { QByteArray data; data.append("hello\r\n"); QHostAddress addr("127.0.0.2"); socket->writeDatagram(data, addr, 56666); }
The Receiver Code in Qt:
int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); MyUDP server; return a.exec(); } MyUDP::MyUDP(QObject *parent) : QObject(parent) { socket = new QUdpSocket(this); QHostAddress addr ("127.0.0.2"); socket->bind(56666); connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead())); } void MyUDP::readyRead() { QByteArray buf; buf.resize(socket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; socket->readDatagram(buf.data(), buf.size(), &sender, &senderPort); qDebug()<<"Message from: "<< sender.toString(); qDebug()<<"Message port: " << senderPort; qDebug()<<"Message: " << buf; }
When the Qt sender sends a "hello", the receiver's readyRead() signal is emitted and prints out the message.
I got the UDP-Sender/Receiver app from the Microsoft App store.
However, when I try to use UDP-Sender/Receiver to either receive or send to the Qt receiver or sender code, it does not work.I also used WireShark to check that the UDP MS App is working and sending "hello" to the correct address/port which is 56666.
Qt Sender code makes a UDP packet and sends it to the port 56666, but UDP MS app can't receive it.
UDP MS app makes a UDP packet and sends it to the port 56666, but Qt UDP Receiver cannot receive it.
Firewalls are down, so that's not the issue.
Thank you for any help in advance!
Also tagging the guru @SGaist -
@kioij
are you sure that the other end is also listening on the loop back address (127.0.0.2)? -
Yes, the sender sends a message to 127.0.0.2:56666 from 127.0.0.1
Yes, the receiver listens to port 56666. -
Hi, if the app you got from the Microsoft Store is a UWP app (I think most of them are) then the behavior you're seeing is by design for security reasons, i.e. UWP apps are blocked from using any IP-number that begins with 127.x.x.x for example 127.0.0.1 and 127.0.0.2.
Perhaps try with an app not from the MIcrosoft Store...