QUDPSocket failing to receive data from Sender
-
Hello, I looked at various examples of QUDPSocket and how to bind & listen on a port that receives data from a remote ip/port.
I'm currently testing it with a random IP and Port with an app that sends UDPs, however it fails to interact and emit the readReady signal.
I'm not sure where the problem is, if you had any suggestions, that would be great.
Thank you in advance for any help.int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); Socket* client = new Socket(); client->initSocket(); return a.exec(); } void Socket::initSocket() { udpSocket = new QUdpSocket(this); connect(udpSocket, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams())); if(!udpSocket->bind(QHostAddress::Any, 5333, QUdpSocket::ShareAddress)) { qDebug() << "bind error"; } } void Socket::readPendingDatagrams() { while(udpSocket->hasPendingDatagrams()) { QByteArray buffer; buffer.resize(udpSocket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; udpSocket->readDatagram(buffer.data(),buffer.size(),&sender,&senderPort); qDebug() << "size"<<udpSocket->pendingDatagramSize(); } }