I'm testing a P2P communication by udp with Qt 5.4(on Windows 10 64bit).
On Windows to Windows, this code can get a message("SendFromHost") from an another device. But on Android to Windows, this code got a own sent message("SendFromGuest") and finished the program.
Please tell me how to get a message without own sent.
void Network::start()
{
findLanSocket = new QUdpSocket(this);
connect(findLanSocket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
this, SLOT(onUdpStateChanged(QAbstractSocket::SocketState)));
findLanSocket->bind(findPort, QUdpSocket::ShareAddress);
QByteArray datagram = "SendFromGuest";
findLanSocket->writeDatagram(datagram.data(), datagram.size(), QHostAddress::Broadcast, findPort);
}
void Network::onUdpStateChanged(QAbstractSocket::SocketState s)
{
if (s == QAbstractSocket::BoundState) {
connect(findLanSocket, SIGNAL(readyRead()), this, SLOT(onReadyUdpRead()));
}
}
void Network::onReadyUdpRead()
{
QByteArray datagram; QHostAddress haddr;
datagram.resize(findLanSocket->pendingDatagramSize());
findLanSocket->readDatagram(datagram.data(), datagram.size(), &haddr);
QString rev = QString::fromUtf8(datagram);
if (rev == "SendFromHost"){
result = haddr.toString();
qDebug() << result;
success();
return;
}
}