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. why is data not transmitted over udp?

why is data not transmitted over udp?

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.15.2udp
5 Posts 2 Posters 841 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.
  • timob256T Offline
    timob256T Offline
    timob256
    wrote on last edited by
    #1

    I'm sending a message by UDP (-9.58924 2) and this is what I get ( "" ) :

    0   1
    str_priem:  ""
    -9.58924   2
    str_priem:  ""
    -5.44021   3
    str_priem:  ""
    6.50288   4
    str_priem:  ""
    9.12945   5
    str_priem:  ""
    -1.32352   6
    str_priem:  ""
    -9.88032   7
    str_priem:  ""
    

    here is the code :

    one sends the other receives

    // тут отправляем сообщение
    void MainWindow::onTimeoutStart()
    {
    
        str_ip = ui->lE_enover_id->text();
        str_port = ui->lE_enover_port->text();
        int_port = str_port.toInt(); // превращаем в инты
    
         // сообщение
        // состоит из двух чисел первое Х второе У
        if(grad >=360 )
        {
            grad = 0;
        }
        data_x = 10 * sin(grad);
        grad = grad + 5;
        if(data_y >= 100)
            data_y = 0;
        data_y = data_y + 1;
    
        //отправка
        QByteArray baDatagram_out;
        QDataStream out(&baDatagram_out, QIODevice::WriteOnly);
        out.setVersion(QDataStream::Qt_5_3);
        qDebug() << data_x << " " << data_y;
        out << data_x;
        out << data_y;
        if(ui->lE_enover_id->text().isEmpty() == true)
        {
            m_pudp->writeDatagram(baDatagram_out, QHostAddress::LocalHost, int_port);
        }
        else
        {
            m_pudp->writeDatagram(baDatagram_out, QHostAddress(str_ip),  int_port);
        }
    }
    

    receive :

    void MainWindow::slotProcessDatagrams()
    {
        QByteArray baDatagram_in;
        do {
            baDatagram_in.resize(m_pudp_in->pendingDatagramSize());
            m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size());
        } while(m_pudp_in->hasPendingDatagrams());
    
        QDataStream in(&baDatagram_in, QIODevice::ReadOnly);
        in.setVersion(QDataStream::Qt_5_3);
        QString str_priem;
        in >>  str_priem;
    
        qDebug() << "str_priem: " << str_priem;
        str_priem.clear();
    }
    

    why does only an empty message arrive without "filling"??

    введите сюда описание изображения

    Christian EhrlicherC timob256T 2 Replies Last reply
    0
    • timob256T timob256

      @Christian-Ehrlicher said in why is data not transmitted over udp?:

      you write two doubles but read a QString - how should this work?

      Thank you for the offer. But alas, I do not know what to write to make it work.

      I am not a mathematician and have no education, please tell me what to write.
      The 3rd grade of junior high school is all I've finished ;_; .

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @timob256 said in why is data not transmitted over udp?:

      Thank you for the offer. But alas, I do not know what to write to make it work.

      When you put two numbers into a QDataStream you should also read two numbers and not a string - this has nothing to do with programming - when you put two apples into a bag you can't get an banana out of it...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • timob256T timob256

        I'm sending a message by UDP (-9.58924 2) and this is what I get ( "" ) :

        0   1
        str_priem:  ""
        -9.58924   2
        str_priem:  ""
        -5.44021   3
        str_priem:  ""
        6.50288   4
        str_priem:  ""
        9.12945   5
        str_priem:  ""
        -1.32352   6
        str_priem:  ""
        -9.88032   7
        str_priem:  ""
        

        here is the code :

        one sends the other receives

        // тут отправляем сообщение
        void MainWindow::onTimeoutStart()
        {
        
            str_ip = ui->lE_enover_id->text();
            str_port = ui->lE_enover_port->text();
            int_port = str_port.toInt(); // превращаем в инты
        
             // сообщение
            // состоит из двух чисел первое Х второе У
            if(grad >=360 )
            {
                grad = 0;
            }
            data_x = 10 * sin(grad);
            grad = grad + 5;
            if(data_y >= 100)
                data_y = 0;
            data_y = data_y + 1;
        
            //отправка
            QByteArray baDatagram_out;
            QDataStream out(&baDatagram_out, QIODevice::WriteOnly);
            out.setVersion(QDataStream::Qt_5_3);
            qDebug() << data_x << " " << data_y;
            out << data_x;
            out << data_y;
            if(ui->lE_enover_id->text().isEmpty() == true)
            {
                m_pudp->writeDatagram(baDatagram_out, QHostAddress::LocalHost, int_port);
            }
            else
            {
                m_pudp->writeDatagram(baDatagram_out, QHostAddress(str_ip),  int_port);
            }
        }
        

        receive :

        void MainWindow::slotProcessDatagrams()
        {
            QByteArray baDatagram_in;
            do {
                baDatagram_in.resize(m_pudp_in->pendingDatagramSize());
                m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size());
            } while(m_pudp_in->hasPendingDatagrams());
        
            QDataStream in(&baDatagram_in, QIODevice::ReadOnly);
            in.setVersion(QDataStream::Qt_5_3);
            QString str_priem;
            in >>  str_priem;
        
            qDebug() << "str_priem: " << str_priem;
            str_priem.clear();
        }
        

        why does only an empty message arrive without "filling"??

        введите сюда описание изображения

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @timob256 you write two doubles but read a QString - how should this work?

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        timob256T 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          @timob256 you write two doubles but read a QString - how should this work?

          timob256T Offline
          timob256T Offline
          timob256
          wrote on last edited by
          #3

          @Christian-Ehrlicher said in why is data not transmitted over udp?:

          you write two doubles but read a QString - how should this work?

          Thank you for the offer. But alas, I do not know what to write to make it work.

          I am not a mathematician and have no education, please tell me what to write.
          The 3rd grade of junior high school is all I've finished ;_; .

          Christian EhrlicherC 1 Reply Last reply
          0
          • timob256T timob256

            @Christian-Ehrlicher said in why is data not transmitted over udp?:

            you write two doubles but read a QString - how should this work?

            Thank you for the offer. But alas, I do not know what to write to make it work.

            I am not a mathematician and have no education, please tell me what to write.
            The 3rd grade of junior high school is all I've finished ;_; .

            Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @timob256 said in why is data not transmitted over udp?:

            Thank you for the offer. But alas, I do not know what to write to make it work.

            When you put two numbers into a QDataStream you should also read two numbers and not a string - this has nothing to do with programming - when you put two apples into a bag you can't get an banana out of it...

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • timob256T timob256

              I'm sending a message by UDP (-9.58924 2) and this is what I get ( "" ) :

              0   1
              str_priem:  ""
              -9.58924   2
              str_priem:  ""
              -5.44021   3
              str_priem:  ""
              6.50288   4
              str_priem:  ""
              9.12945   5
              str_priem:  ""
              -1.32352   6
              str_priem:  ""
              -9.88032   7
              str_priem:  ""
              

              here is the code :

              one sends the other receives

              // тут отправляем сообщение
              void MainWindow::onTimeoutStart()
              {
              
                  str_ip = ui->lE_enover_id->text();
                  str_port = ui->lE_enover_port->text();
                  int_port = str_port.toInt(); // превращаем в инты
              
                   // сообщение
                  // состоит из двух чисел первое Х второе У
                  if(grad >=360 )
                  {
                      grad = 0;
                  }
                  data_x = 10 * sin(grad);
                  grad = grad + 5;
                  if(data_y >= 100)
                      data_y = 0;
                  data_y = data_y + 1;
              
                  //отправка
                  QByteArray baDatagram_out;
                  QDataStream out(&baDatagram_out, QIODevice::WriteOnly);
                  out.setVersion(QDataStream::Qt_5_3);
                  qDebug() << data_x << " " << data_y;
                  out << data_x;
                  out << data_y;
                  if(ui->lE_enover_id->text().isEmpty() == true)
                  {
                      m_pudp->writeDatagram(baDatagram_out, QHostAddress::LocalHost, int_port);
                  }
                  else
                  {
                      m_pudp->writeDatagram(baDatagram_out, QHostAddress(str_ip),  int_port);
                  }
              }
              

              receive :

              void MainWindow::slotProcessDatagrams()
              {
                  QByteArray baDatagram_in;
                  do {
                      baDatagram_in.resize(m_pudp_in->pendingDatagramSize());
                      m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size());
                  } while(m_pudp_in->hasPendingDatagrams());
              
                  QDataStream in(&baDatagram_in, QIODevice::ReadOnly);
                  in.setVersion(QDataStream::Qt_5_3);
                  QString str_priem;
                  in >>  str_priem;
              
                  qDebug() << "str_priem: " << str_priem;
                  str_priem.clear();
              }
              

              why does only an empty message arrive without "filling"??

              введите сюда описание изображения

              timob256T Offline
              timob256T Offline
              timob256
              wrote on last edited by
              #5

              @timob256 this work

              QString data_str = QString::number(data_x)+ " "+QString::number(data_y);
              
              out << data_str;
              
              qDebug() <<data_str ;
              

              введите сюда описание изображения

              1 Reply Last reply
              0
              • timob256T timob256 has marked this topic as solved on

              • Login

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