Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    How to get destination address of a received UDP packet in Qt (solved)

    Mobile and Embedded
    1
    1
    1043
    Loading More Posts
    • 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.
    • H
      houmingc last edited by

      i am able to grab datagram from server but i can't find its destination IP from the UDP received. Can advice how to grab server destination IP and saved it to a variable. How to get destination address of a received UDP packet

      socketudp::processPendingDatagrams()
      {
      QByteArray datagram;
      datagram.resize(udpSocket->pendingDatagramSize());
      datagram.fill(0,udpSocket->pendingDatagramSize());

      udpSocket->readDatagram(datagram.data(),datagram.size());
      emit ipDataReceived(datagram);
      

      }

      void socketudp::onUDPportDataReceived(QByteArray UDPdataRec)
      {
      QDataStream in(UDPdataRec);
      qint8 a;
      qint32 b;
      in>>a>>b;
      }

      ===========================
      There is another method for readDatagram that will achieve receiving sender ip address.
      readDatagram(datagram.data(), datagram.size(),&sender, &senderPort);
      declare two private variable in the header file
      -QHostAddress sender;
      -quint16 senderPort

      QString ipDestination;
      ipDestination=sender.toString();

      1 Reply Last reply Reply Quote 0
      • First post
        Last post