|
@@ -0,0 +1,16 @@
|
|
|
+QUdpSocket* m_udpSocket = nullptr;
|
|
|
+ m_udpSocket = new QUdpSocket(this);
|
|
|
+ m_udpSocket->bind(QHostAddress::Any, 8776);
|
|
|
+ connect(m_udpSocket, &QUdpSocket::readyRead, this, [this](){
|
|
|
+ while(m_udpSocket->hasPendingDatagrams())
|
|
|
+ {
|
|
|
+ QByteArray datagram;
|
|
|
+ QHostAddress address;
|
|
|
+ quint32 ipAddress;
|
|
|
+ datagram.resize(m_udpSocket->pendingDatagramSize());
|
|
|
+ qint64 bytesRead = m_udpSocket->readDatagram(datagram.data(), datagram.size(), &address);
|
|
|
+ ipAddress = address.toIPv4Address();
|
|
|
+ QString ipAddressString = QString("%1.%2.%3.%4").arg((ipAddress>>24) & 0xFF).arg((ipAddress>>16) & 0xFF).arg((ipAddress>>8) & 0xFF).arg((ipAddress) & 0xFF);
|
|
|
+ qDebug() << datagram.data() << ipAddressString;
|
|
|
+ }
|
|
|
+ });
|