Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to get destination address of a received UDP packet in Qt (solved)

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

Scheduled Pinned Locked Moved Mobile and Embedded
1 Posts 1 Posters 1.3k Views 1 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.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by
    #1

    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
    0

    • Login

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