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 - don't receive data
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket - don't receive data

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 884 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.
  • T Offline
    T Offline
    TomNow99
    wrote on last edited by TomNow99
    #1

    Hello,

    I would like to send data from Linux Qt App to Windows Qt App and next when windows app receive data I want to send data from windows app to linux app.

    I can send data from linux to windows - I see the message, but my linux app don't receive data from windows.

    Windows: 192.168.0.73
    Linux: 192.168.0.122

    Codes:
    Windows:

        socket = new QUdpSocket;
        socket->bind(QHostAddress::Any,7212);
        socket2 = new QUdpSocket;
        connect(socket, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
    
    And in readyReadSlot():
    
        QByteArray b;
        b.resize(socket->pendingDatagramSize());
        QHostAddress host;
        quint16 port;
        socket->readDatagram(b.data(),b.size(),&host,&port);
    
        …
    
        QByteArray byte;
        byte.append("nooo!!!");
    
        qDebug()<<socket2->writeDatagram(byte.data(),byte.count(),QHostAddress("192.168.0.122"),7213);
    

    Linux code:

        socket = new QUdpSocket;
        socket2 = new QUdpSocket;
        socket2->bind(QHostAddress::Any,7213);
        connect(socket2, SIGNAL(readyRead()),this,SLOT(readyReadSlot()));
    
    In clicked() slot:
            QByteArray byte;
            byte.append("abc");
            socket->writeDatagram(byte, byte.count(), QHostAddress("192.168.0.73"), 7212);
    
    In readReadSlot:
    void MainWindow::readyReadSlot()
    {
        qqDebug()<<"something";
        QByteArray byte;
        byte.resize(socket2->pendingDatagramSize());
        socket2->readDatagram(byte.data(),byte.size());
        qInfo()<<byte.data();
    }
    

    qDebug() in windows says: 7, so this is correct numer of send bytes. In linux I don't see qDebug() "something" and message.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you sure the Windows firewall does not block that port coming inside ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TomNow99
        wrote on last edited by TomNow99
        #3

        @SGaist Yes. I turn off the Windows firewall.

        EDIT Even when windows firewall is turn on- it doesn't block comming messages - I add exception.

        I think the problem is on the linux side.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Check the network traffic with a tool like WireShark.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • T Offline
            T Offline
            TomNow99
            wrote on last edited by
            #5

            @SGaist When I use tcpdump on linux:

            tcpdump port 7213
            

            I get:

            (time) IP 192.168.0.73.49913 > localhost.localdomain.7213: UDP, length 7
            

            I don't understand this "49913" in IP address after windows IP

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              From a quick check of the tcpdump man page, it's the port number used to connect to your machine.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • T Offline
                T Offline
                TomNow99
                wrote on last edited by
                #7

                @SGaist But why? On Windows I have:

                qDebug()<<socket2->writeDatagram(byte.data(),byte.count(),QHostAddress("192.168.0.122"),7213);
                

                So I use 7213.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  That's the target port of the remote machine not the one used by the source machine.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    TomNow99
                    wrote on last edited by TomNow99
                    #9

                    @SGaist So tcpdump says: "everything is ok with sending datagram from windows"?

                    EDIT @SGaist The problem was... linux have problem with qDebug… Thanks for help @SGaist ! I know linux receive datagram because I change text in QLabel ;)

                    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