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 stop receiving data
Forum Updated to NodeBB v4.3 + New Features

QUdpSocket stop receiving data

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 6 Posters 7.7k Views 2 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.
  • N Offline
    N Offline
    nanthiran_2005
    wrote on last edited by A Former User
    #1

    Hi everyone,

    I am currently trying to receive data in QT from Matlab within a localhost. The Matlab application is sending 176 bytes of data at a certain period. I have been observing the data received by Qt, using a variable that keep counts of the total number of bytes received. Initially, Qt is receiving the data without any problem. However, after sometime Qt stop receiving the data although Matlab is sending the data properly. What could have stopped the QUdpSocket from receiving the data (QUdpSocket stop emitting readyRead() signal)?

    And is there a way to overcome this issue? For example, initializing a timer that reset the socket if no data is received in a period of time

    Note:
    1)The QUdpSocket is running in a worker thread.
    2) Qt Version 5.3
    3) The number of bytes received by Qt before it stops receiving varies. In first trial it managed to receive a total of 41kB. Second iteration 32kB and so on.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      Is it possible something else is getting the udp data? UDP data is only sent once and can only be received once, but any UDP socket can receive and keep it.

      Maybe you have some other app on your system intercepting that data after a while?

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        I suspect the issue with reading. Can you check how you are processing the data ? You may not be reading the data in some condition. unless you read the data readyRead signal will not be emitted.

        Can you check if thread is still running ? I know this is remote chance.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nanthiran_2005
          wrote on last edited by
          #4

          Hi guys,

          Thanks for the input. I think I have solved the issue. The threads are running fine. It turned out that, this problem occurs when I create the UDP socket in the worker thread class without passing its parent.

          i.e
          Instead of declaring :
          @QUdpSocket *socket = new QUdpSocket;@

          It should be:
          @QUdpSocket *socket = new QUdpSocket(this);@

          After fixing this, I could continuously receive data with a period of 25ms without any disruption.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by
            #5

            That's kinda weird. I'm glad it's solved for now, but I can't really see any cases where having a parent would matter for receiving data.

            Especially since it would receive some but not all the data. Very weird indeed. Glad it's working though.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nanthiran_2005
              wrote on last edited by
              #6

              Exactly. I find it very weird though. And I am still not sure how this could solve the problem. But I have tested more than once and it is no longer failing. If I remove the parent, it fails.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                ambershark
                wrote on last edited by
                #7

                Just out of curiousity, what type of object is "this"?

                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  nanthiran_2005
                  wrote on last edited by
                  #8

                  "this" is just a class I created myself to receive and process the data. After processing, it emit signals by transmitting the data received as a parameter to some other class. I have inherited the class from QObject though and it runs in a worker thread

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ambershark
                    wrote on last edited by
                    #9

                    Hmm, so no reason there. Oh well, I'll stop thinking about it now since it's working for you. I just hate not knowing why something works, lol. :)

                    My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      nanthiran_2005
                      wrote on last edited by
                      #10

                      Same here. :)

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

                        Hi,

                        Just an educated guess, you wrote that the socket is in a worker thread so I presume that it's a worker object that you used moveToThread on ? If so, the socket was not moved before since it wasn't parented to the worker object and thus was not in the correct thread to work.

                        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
                        • N Offline
                          N Offline
                          nanthiran_2005
                          wrote on last edited by
                          #12

                          Yes, I used moveToThread from the main thread. That makes so much sense. Thanks SGaist

                          1 Reply Last reply
                          0
                          • SurizerS Offline
                            SurizerS Offline
                            Surizer
                            wrote on last edited by
                            #13

                            Hey is it possible to share how you are sending data from matlab to QT .How did you set up both environment? It would be nice if you can share something.

                            K 1 Reply Last reply
                            0
                            • SurizerS Surizer

                              Hey is it possible to share how you are sending data from matlab to QT .How did you set up both environment? It would be nice if you can share something.

                              K Offline
                              K Offline
                              koahnig
                              wrote on last edited by
                              #14

                              @Surizer
                              Hi and welcome to this forum

                              Just make you aware that the post is rather old. Furthermore from the user's profile you can see that the user might no longer hang out in the forum. His last activity was about 2 years according to his profile.

                              Possibly you start a new thread with a link to this thread here. May be someone else knows a solution.

                              Vote the answer(s) that helped you to solve your issue(s)

                              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