How to get destination address of a received UDP packet in Qt (solved)
-
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 senderPortQString ipDestination;
ipDestination=sender.toString();