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. Can we receive large (1064) udp datagram
Forum Updated to NodeBB v4.3 + New Features

Can we receive large (1064) udp datagram

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 5 Posters 864 Views 2 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.
  • S Sowjanya

    Hi
    I want to use Qt UDP (not TCP) socket to recieve.I tried to recieve small packets like 15 bytes in qt .Small packets are recieving properly but while i tried to recieve 1064 packets data QT is not recieving properly ,However i can recieve full data in wireshark .
    Here is my normal code

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    socket = new QUdpSocket(this);
    socket->bind(QHostAddress("192.168.10.1"),64826));
    connect(socket,SLOT(readyread(),this,SLOT(readdata());
    }
    void MainWindow::readdata()
    {
    QHostAddress sender;
    quint16 port;
    QByteArray buffer;
    QByteArray Data;
    buffer.resize(socket1->pendingDatagramSize());
    socket1->readDatagram(buffer.data(),buffer.size(),&sender,&senderport);
    qDebug()<<"sender"<<sender;
    qDebug()<<"data"<<buffer;
    }

    Can anyone help me ,Thanks.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Sowjanya In what way it does not work for big packets?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    1
    • S Offline
      S Offline
      Sowjanya
      wrote on last edited by
      #3

      @jsulm through fpga i tried to recieve packets

      jsulmJ 1 Reply Last reply
      0
      • S Sowjanya

        @jsulm through fpga i tried to recieve packets

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @Sowjanya said in Can we recieve large(1064) udp datagram:

        i tried to recieve packets

        And what happened?
        What exactly did not work?
        Can you be more precise?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Sowjanya
          wrote on last edited by
          #5

          @jsulm i sent data to fpga through that i recieved some thousands of packets ,which are in 1064(lenth) .In wireshark i can able to see ,but in qt only some packets are recieving
          ex:12mb data
          i am getting 1mb data

          J.HilkJ jsulmJ 2 Replies Last reply
          0
          • S Sowjanya

            @jsulm i sent data to fpga through that i recieved some thousands of packets ,which are in 1064(lenth) .In wireshark i can able to see ,but in qt only some packets are recieving
            ex:12mb data
            i am getting 1mb data

            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #6

            @Sowjanya well it's udp so there is no guarantee that your datagram comes in one go (especially filtered through the OS and Qt interface)

            You have to impose some kind of protocol on it, so that you know this chunk of bytes is one coherent datagram and the next one belongs to an other one.

            You need error checking as well, your datagram may loos bytes


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            5
            • S Sowjanya

              @jsulm i sent data to fpga through that i recieved some thousands of packets ,which are in 1064(lenth) .In wireshark i can able to see ,but in qt only some packets are recieving
              ex:12mb data
              i am getting 1mb data

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @Sowjanya Please take a look at the example in https://doc.qt.io/qt-5/qudpsocket.html
              In your slot you should read as long as there are still pending datagrams:

              while (udpSocket->hasPendingDatagrams()) {
                  QNetworkDatagram datagram = udpSocket->receiveDatagram();
                  processTheDatagram(datagram);
              }
              

              In your current code you only read one datagram.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              S 2 Replies Last reply
              7
              • jsulmJ jsulm

                @Sowjanya Please take a look at the example in https://doc.qt.io/qt-5/qudpsocket.html
                In your slot you should read as long as there are still pending datagrams:

                while (udpSocket->hasPendingDatagrams()) {
                    QNetworkDatagram datagram = udpSocket->receiveDatagram();
                    processTheDatagram(datagram);
                }
                

                In your current code you only read one datagram.

                S Offline
                S Offline
                Sowjanya
                wrote on last edited by
                #8
                This post is deleted!
                1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Sowjanya Please take a look at the example in https://doc.qt.io/qt-5/qudpsocket.html
                  In your slot you should read as long as there are still pending datagrams:

                  while (udpSocket->hasPendingDatagrams()) {
                      QNetworkDatagram datagram = udpSocket->receiveDatagram();
                      processTheDatagram(datagram);
                  }
                  

                  In your current code you only read one datagram.

                  S Offline
                  S Offline
                  Sowjanya
                  wrote on last edited by
                  #9

                  @jsulm
                  Hi i again tried like this,but i cant able to recieve properly
                  {
                  ui->setupUi(this);
                  socket = new QUdpSocket(this);
                  socket->bind(QHostAddress("192.168.10.1"),64826));
                  connect(socket,SLOT(readyread(),this,SLOT(readdata());
                  }
                  void MainWindow::readdata()
                  {
                  QHostAddress sender;
                  quint16 port;
                  QByteArray buffer;
                  QByteArray Data;
                  while (socket->hasPendingDatagrams())
                  {
                  QNetworkDatagram datagram = socket->receiveDatagram();
                  qDebug()<<"data"<<datagram.data();
                  // processTheDatagram(datagram);
                  }
                  }

                  JonBJ Pablo J. RoginaP 2 Replies Last reply
                  0
                  • S Sowjanya

                    @jsulm
                    Hi i again tried like this,but i cant able to recieve properly
                    {
                    ui->setupUi(this);
                    socket = new QUdpSocket(this);
                    socket->bind(QHostAddress("192.168.10.1"),64826));
                    connect(socket,SLOT(readyread(),this,SLOT(readdata());
                    }
                    void MainWindow::readdata()
                    {
                    QHostAddress sender;
                    quint16 port;
                    QByteArray buffer;
                    QByteArray Data;
                    while (socket->hasPendingDatagrams())
                    {
                    QNetworkDatagram datagram = socket->receiveDatagram();
                    qDebug()<<"data"<<datagram.data();
                    // processTheDatagram(datagram);
                    }
                    }

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #10

                    @Sowjanya said in Can we receive large (1064) udp datagram:

                    but i cant able to recieve properly

                    Code looks about right to me. Please don't say just "but i cant able to recieve properly", you have debug statement there, why not tell people what it did/did not output? Or do you prefer people trying to help should just have to guess for themselves?

                    1 Reply Last reply
                    1
                    • S Sowjanya

                      @jsulm
                      Hi i again tried like this,but i cant able to recieve properly
                      {
                      ui->setupUi(this);
                      socket = new QUdpSocket(this);
                      socket->bind(QHostAddress("192.168.10.1"),64826));
                      connect(socket,SLOT(readyread(),this,SLOT(readdata());
                      }
                      void MainWindow::readdata()
                      {
                      QHostAddress sender;
                      quint16 port;
                      QByteArray buffer;
                      QByteArray Data;
                      while (socket->hasPendingDatagrams())
                      {
                      QNetworkDatagram datagram = socket->receiveDatagram();
                      qDebug()<<"data"<<datagram.data();
                      // processTheDatagram(datagram);
                      }
                      }

                      Pablo J. RoginaP Offline
                      Pablo J. RoginaP Offline
                      Pablo J. Rogina
                      wrote on last edited by
                      #11

                      @Sowjanya said in Can we receive large (1064) udp datagram:

                      i cant able to recieve properly

                      In addition to @JonB suggested, you may want to analyze network traffic to/from your Qt app by means of Wireshark to confirm what data is actually flowing back and forth in the connection...

                      Upvote the answer(s) that helped you solve the issue
                      Use "Topic Tools" button to mark your post as Solved
                      Add screenshots via postimage.org
                      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                      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