How i can determine size of buffer.data() in udp socket in Qt?



  • hi,
    when i use resize buffer udp to 1MB, and received Data is less than 1MB, how i can determine size of buffer.data() in udp socket???

     void MyUDP::readyRead()     //Read something
    {
      QByteArray Buffer;
      Buffer.resize(1000000);
      
      QHostAddress sender;
      quint16 senderPort;
      socket->readDatagram(Buffer.data(),Buffer.size(),&sender,&senderPort);
      
      //The address will be sender.toString()
    }
    

    i can not find any method that work for data size not buffer size

    even i test

    void MyUDP::readyRead()     //Read something
    {
      QByteArray Buffer;
      Buffer.resize(socket->pendingDatagramSize());
      
      QHostAddress sender;
      quint16 senderPort;
      socket->readDatagram(Buffer.data(),Buffer.size(),&sender,&senderPort);
      
      //The address will be sender.toString()
    }
    

    **in ubuntu when i send data 1MB, it can not received all data,
    some of data will be lost. it received 50k data.
    my sender 1MB is python socket , when i send 1MB to udp c++ Qt, when i used socket-
    i can not received all data some of data is lost. because python send file 1MB in 10 step.
    we can not increase size MTU that is 65535 for udp in linux,so python can not send all data in onestep.........

    >pendingDatagramSize()socket->pendingDatagramSize()
    

    so i used up method all data i can received but i can not determine size of buffer.data()**
    thanks for replies
    best regards stackprogramer


  • Moderators

    @stackprogramer First thing to do: read documentation (http://doc.qt.io/qt-5/qudpsocket.html#readDatagram)
    readDatagram() returns the size of the datagram:
    "Returns the size of the datagram on success; otherwise returns -1."


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.