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 cannot receive datagram
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket cannot receive datagram

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.4k 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.
  • E Offline
    E Offline
    Emanuele96
    wrote on last edited by Emanuele96
    #1

    Hi, I'm trying to receive datagrams from a Raspberry. where I use Linux native sockets to send them. It is not the first time I use QUdpSocket and I'm quite familiar with Qt sockets functionalities thus it is very strange that I'm dealing with this problem.
    Briefly although Wireshark is able to sniff all the packets I expect to receive, it seems that no one of them is received by QUdpSocket since it doesn't emit any readyRead() signal. I also tried to inhibit the firewall... nothing to do. I really don't understand if the problem is in my code or if in a detail that currently I can't catch. However this is my code:

    Listener::Listener(QWidget *parent) : QMainWindow(parent)
    {
        std::cout<<"ip addresses list:"<<std::endl;
        int i = 0;
        for(QHostAddress addr: QNetworkInterface::allAddresses())
            std::cout<<"address "<<++i<<": "<<addr.toString().toStdString()<<std::endl;
        
    
        skt = new QUdpSocket(this);
        std::cout<<std::endl<<"Please select address to bind: "<<std::endl;
        scanf("%d",&i);
        auto addr = QNetworkInterface::allAddresses()[i-1];
        std::cout<<"binding to address: "<<addr.toString().toStdString()<<std::endl;
    
        if(!skt->bind(QHostAddress(addr),5555))
            std::cout<<"can't bind!"<<std::endl;
    
        connect(skt,&QUdpSocket::readyRead,this,&Listener::readPacket);
    
        log = new QTextEdit(this);
        this->setCentralWidget(log);
    }
    
    void Listener::readPacket(){
        char data[100];
    
        std::cout<<"arrived"<<std::endl;
        log->append("arrived");
    
        skt->readAll();
    }
    

    please don't focus on the usefullness of readPacket(), it only needs to let me understand if readyRead signal is emitted.
    Can anyone help me?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Emanuele96
      wrote on last edited by
      #8

      Guys, thank you very much for help, I just realised that I built exception for windows defender firewall but not for avast one. It definitely was the firewall, thank you for your time anyway. Regards.

      1 Reply Last reply
      0
      • Kent-DorfmanK Offline
        Kent-DorfmanK Offline
        Kent-Dorfman
        wrote on last edited by Kent-Dorfman
        #2

        first thing you should do is simplify by binding to the default 0.0.0.0 address instead of a specific interface...then look at lsof -i to confirm the listener is active.

        After than send some UDP to it via socat or nc

        If you meet the AI on the road, kill it.

        E 1 Reply Last reply
        0
        • Kent-DorfmanK Kent-Dorfman

          first thing you should do is simplify by binding to the default 0.0.0.0 address instead of a specific interface...then look at lsof -i to confirm the listener is active.

          After than send some UDP to it via socat or nc

          E Offline
          E Offline
          Emanuele96
          wrote on last edited by
          #3

          @Kent-Dorfman said in QUdpSocket cannot receive datagram:

          lsof

          Yes of course i tried also with more general bindings but it is exactly the same. Then I also listened to your advice by using socat for testing at least the reception but, again, nothing to do. I forgot to say that i'm developing the Listener on Windows 10, so I should find another way to make sure that the socket is active.

          1 Reply Last reply
          0
          • nageshN Offline
            nageshN Offline
            nagesh
            wrote on last edited by
            #4

            @Emanuele96 Hope the application binds to specified address successfully,
            if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,

            Do you verify the wireshark data is addressed to the the required address and port number (5555)?

            E 1 Reply Last reply
            0
            • nageshN nagesh

              @Emanuele96 Hope the application binds to specified address successfully,
              if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,

              Do you verify the wireshark data is addressed to the the required address and port number (5555)?

              E Offline
              E Offline
              Emanuele96
              wrote on last edited by
              #5

              @nagesh they are all trials i performed yet. I'm sure that it is correctly binded because if i send a message wireshark catch a packet as address source the correct one and port source 5555, as specified in the code

              1 Reply Last reply
              0
              • nageshN Offline
                nageshN Offline
                nagesh
                wrote on last edited by
                #6

                @nagesh said in QUdpSocket cannot receive datagram:

                if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,

                Have you checked this?..in the same application send the data to required port & receive the data

                E 1 Reply Last reply
                0
                • nageshN nagesh

                  @nagesh said in QUdpSocket cannot receive datagram:

                  if so try to send some sample data from the same application so as to verify whether it receives the data to the required port(5555) from the same machine,

                  Have you checked this?..in the same application send the data to required port & receive the data

                  E Offline
                  E Offline
                  Emanuele96
                  wrote on last edited by
                  #7

                  @nagesh yes, I tried and nothing arrives to the listener. According to me it is not a problem of senders cause, once again, Wireshark can hear all the packets i send to my listener...

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    Emanuele96
                    wrote on last edited by
                    #8

                    Guys, thank you very much for help, I just realised that I built exception for windows defender firewall but not for avast one. It definitely was the firewall, thank you for your time anyway. Regards.

                    1 Reply Last reply
                    0

                    • Login

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