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. UDP broadcast
QtWS25 Last Chance

UDP broadcast

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 3.2k Views
  • 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.
  • 3l3v3n3 Offline
    3l3v3n3 Offline
    3l3v3n
    wrote on last edited by 3l3v3n
    #1
    Hi, I'm finding since two days how to sent a UDP broadcast. I have seen many examples (also the broadcastReceiver and broadcastSender on the qt web site) but 
    

    their are still not working for me. When I try to send a broadcast, the method QUdpSocket::writeDatagram(..) returns -1 and the datas are not transmitted. The errorString() method returns "unable to send a message". I'm on ubuntu 14.04 x64. I wish to know if there is a particular manipulation that i should do to make this broadcast work. thanks and sorry for my english level.

    Joel BodenmannJ 1 Reply Last reply
    0
    • 3l3v3n3 3l3v3n
      Hi, I'm finding since two days how to sent a UDP broadcast. I have seen many examples (also the broadcastReceiver and broadcastSender on the qt web site) but 
      

      their are still not working for me. When I try to send a broadcast, the method QUdpSocket::writeDatagram(..) returns -1 and the datas are not transmitted. The errorString() method returns "unable to send a message". I'm on ubuntu 14.04 x64. I wish to know if there is a particular manipulation that i should do to make this broadcast work. thanks and sorry for my english level.

      Joel BodenmannJ Offline
      Joel BodenmannJ Offline
      Joel Bodenmann
      wrote on last edited by
      #2

      Hello and welcome!

      Is the actual Broadcast Sender example working for you?
      It would be helpful if you could show us your (relevant) code.

      Industrial process automation software: https://simulton.com
      Embedded Graphics & GUI library: https://ugfx.io

      1 Reply Last reply
      0
      • 3l3v3n3 Offline
        3l3v3n3 Offline
        3l3v3n
        wrote on last edited by
        #3

        Thank for you reply. the actual example doesn't work for me.
        Here is my code:

         envoyeurUDP=new QUdpSocket(this);
            recepteurUDP=new QUdpSocket(this);
            //démarrage du serveur pour UDP
            if (!recepteurUDP->bind(QHostAddress::AnyIPv4,8787,QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint)) {
              qDebug("Impossible de créer la socket en écoute");
             exit(EXIT_FAILURE);
            }
        
            connect(recepteurUDP, SIGNAL(readyRead()), this, SLOT(lireDatagrams()));
        
        
        void FileTransferManager::lireDatagrams(){
            
            char* donnees;
            while (recepteurUDP->hasPendingDatagrams()) {
                    QByteArray datagram;
                    datagram.resize(recepteurUDP->pendingDatagramSize());
                    recepteurUDP->readDatagram(datagram.data(), datagram.size());
                    donnees=datagram.data();
                }
        }
        

        and this one to send datagrams

        void FileTransferManager::sendDatagram(string msg, QHostAddress addr){
            QByteArray datagram=msg.data();
                qint64 r=envoyeurUDP->writeDatagram(datagram.data(), datagram.size(),  addr, 7878);
        }
        
        
        

        and i use it like this :
        fileManager.sendDatagram("blabla",QHostAddress::Broadcast);

        1 Reply Last reply
        0
        • 3l3v3n3 Offline
          3l3v3n3 Offline
          3l3v3n
          wrote on last edited by
          #4

          here is the output of my ifconfig command:

          eth0 Link encap:Ethernet HWaddr f8:a9:63:2d:89:ff
          UP BROADCAST MULTICAST MTU:1500 Metric:1 Packets reçus:0 erreurs:0 :0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 lg file transmission:1000 Octets reçus:0 (0.0 B) Octets transmis:0 (0.0 B)

          lo Link encap:Boucle locale
          inet adr:127.0.0.1 Masque:255.0.0.0 adr inet6: ::1/128 Scope:Hôte UP LOOPBACK RUNNING MTU:65536 Metric:1 Packets reçus:5311 erreurs:0 :0 overruns:0 frame:0 TX packets:5311 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 lg file transmission:0 Octets reçus:661728 (661.7 KB) Octets transmis:661728 (661.7 KB)

          wlan0 Link encap:Ethernet HWaddr b8:ee:65:ab:4f:77
          inet adr:10.42.0.1 Bcast:10.42.0.255 Masque:255.255.255.0 adr inet6: fe80::baee:65ff:feab:4f77/64 Scope:Lien UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Packets reçus:14069 erreurs:0 :0 overruns:0 frame:0 TX packets:15529 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 lg file transmission:1000 Octets reçus:6007592 (6.0 MB) Octets transmis:2307422 (2.3 MB)

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            How do you know it doesn't work ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • 3l3v3n3 Offline
              3l3v3n3 Offline
              3l3v3n
              wrote on last edited by
              #6

              writedatagram() returns -1 ,error() returns SocketError::NetworkError

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I've missed a point in one of your answer. Did I understand correctly that the "Broadcast Sender Example" failed for you ?

                If so, then before trying to debug your application, you should check what makes the example fail. The code doesn't mix both sending and receiving.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  LuGRU
                  wrote on last edited by
                  #8

                  What's size of data? If it's > 512 bytes it will fail.

                  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