Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QUDPSocket failing to receive data from Sender
Forum Updated to NodeBB v4.3 + New Features

QUDPSocket failing to receive data from Sender

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 150 Views
  • 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.
  • K Offline
    K Offline
    kioij
    wrote on last edited by
    #1

    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();
        }
    }
    
    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