Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUDPSocket failing to communicate with any other environment
Forum Updated to NodeBB v4.3 + New Features

QUDPSocket failing to communicate with any other environment

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 380 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kioij
    wrote on last edited by
    #1

    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.
    Capture.PNG

    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.

    Capture.PNG

    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.
    Capture.PNG

    Firewalls are down, so that's not the issue.

    Thank you for any help in advance!
    Also tagging the guru @SGaist

    raven-worxR 1 Reply Last reply
    0
    • K kioij

      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.
      Capture.PNG

      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.

      Capture.PNG

      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.
      Capture.PNG

      Firewalls are down, so that's not the issue.

      Thank you for any help in advance!
      Also tagging the guru @SGaist

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @kioij
      are you sure that the other end is also listening on the loop back address (127.0.0.2)?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      K 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @kioij
        are you sure that the other end is also listening on the loop back address (127.0.0.2)?

        K Offline
        K Offline
        kioij
        wrote on last edited by
        #3

        @raven-worx

        Yes, the sender sends a message to 127.0.0.2:56666 from 127.0.0.1
        Yes, the receiver listens to port 56666.

        1 Reply Last reply
        0
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          4

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved