Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. The problem with QNetwork: receiving UDP broadcast on android device

The problem with QNetwork: receiving UDP broadcast on android device

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 535 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    ovzap
    wrote on last edited by ovzap
    #1

    Actually I’d like to receive UDP broadcast on android device from other simple device (sender UDP broadcast). Both devices are in the same local network. The UDP datagrams are receiving from the Sender, but there is a problem with time of receiving… very long delaying – about 785 seconds! I sure, that the Sender has issued the UDP packet immediately (I have checked it by tcpdump on other computer in the same local network), but on the android device (which receiving UDP) the "bind" has send readReady signal only after the 785 seconds (exactly the same delaying for each datagram).
    Environment: Qt 6.4, IBM-jdk-11.0.17+8, SDK android-31, NDK25.1.8937393, android device Huawei. (NOTE: Additionally I’v checked it with different version of Qt, JDK, SDK and NDK – but have the same result). Compilation without any errors/warnings. It seems to me, that there is some firewall in the Huawei device... May be I need to add some special permission in the androidmanifest? Please advice.

    For example the test project:
    NOTE:

    1. The "Sender" is sending the UDP datagram with time of issuing (format: "hh:mm:ss").
    2. This example code is working properly on the Ubuntu computer (It is receiving the UDP immediately).
    3. I'v checked with different model of mobile phone with the same result... but all of this mobile phone - is Huawei (Unfortunately, I have not any other vendor of phone for test).

    UdpClient.pro

    TEMPLATE     = app
    QT          += widgets network
    SOURCES      = main.cpp \
                   UdpClient.cpp
    HEADERS      = UdpClient.h
    windows:TARGET = ../UdpClient
    

    UdpClient.h

    #pragma once
    #include <QTextEdit>
    class QUdpSocket;
    class UdpClient : public QTextEdit {
    Q_OBJECT
    private:
        QUdpSocket* m_pudp;
    public:
        UdpClient(QWidget* pwgt = 0);
    private slots:
        void slotProcessDatagrams();
    };
    

    main.cpp

    #include <QApplication>
    #include "UdpClient.h"
    int main(int argc, char** argv)
    {
        QApplication app(argc, argv);
        UdpClient    client;
        client.show();
        return app.exec();
    }
    

    UdpClient.cpp

    #include <QtNetwork>
    #include <QtGui>
    #include "UdpClient.h"
    UdpClient::UdpClient(QWidget* pwgt /*=0*/) : QTextEdit(pwgt)
    {
        setWindowTitle("UdpClient");
        m_pudp = new QUdpSocket(this);
        m_pudp->bind(QHostAddress::AnyIPv4, 49100, QUdpSocket::ShareAddress);
        connect(m_pudp, SIGNAL(readyRead()), SLOT(slotProcessDatagrams()));
        append("Test UDP bind:");
    }
    void UdpClient::slotProcessDatagrams()
    {
        QByteArray baDatagram;
        do {
            baDatagram.resize(m_pudp->pendingDatagramSize());
            m_pudp->readDatagram(baDatagram.data(), baDatagram.size());
        } while(m_pudp->hasPendingDatagrams());
        QDateTime dateTime;
        QTime   Time;
        qint64   i_dTime;
        QTime   sentTime;
        dateTime = QDateTime::currentDateTime();
        Time = dateTime.time();
        sentTime = QTime::fromString(QString::fromUtf8(baDatagram) ,"hh:mm:ss");
        i_dTime = sentTime.secsTo(Time);
        append("R"+ QString::number(baDatagram.size()) + "b:" + Time.toString("hh:mm:ss") + "-" + QString(baDatagram) + "=" + QString::number(i_dTime));
    }
    
    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