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. readyRead of a socket in a seperate thread

readyRead of a socket in a seperate thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
socketthreadreadyread
6 Posts 3 Posters 3.4k 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.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by McLion
    #1

    Hi

    I have a socket that I create in my GUI thread. It is used to send status information to a server.
    The server sends a confirmation back for every protocol that I receive with readyRead (connected SIGNAL).

    This all works as expected - except if when multiple messages are sent from within a single function and the loop is of course not calling readyRead before the function ends.

    There is nothing lost. However, I actually would like to have the last transmission confirmed when/before the next message is sent because I use the sequence numbering and status of the ack as part of any message to quickly discover communication issues.

    I suspect, the only solution is to put the socket communication into a separate thread.
    Is there an easier way, maybe to put the readyRead only to separate thread or anything alike that I haven't been thinking of?

    Thanks,
    McL

    1 Reply Last reply
    0
    • Hamed.MasafiH Offline
      Hamed.MasafiH Offline
      Hamed.Masafi
      wrote on last edited by
      #2

      If you want to create a multi-threaded socket server put each socket in a separate QThread. Note that QSocket should be created in related QThread. I have a multi-threaded socket server in my library, you can take a look at it.
      https://github.com/HamedMasafi/Noron

      Remote object sharing (OO RPC)
      http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

      Advanced, Powerful and easy to use ORM for Qt5
      https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        You can use waitForBytesWritten() at every cycle

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        McLionM 1 Reply Last reply
        0
        • VRoninV VRonin

          You can use waitForBytesWritten() at every cycle

          McLionM Offline
          McLionM Offline
          McLion
          wrote on last edited by
          #4

          @VRonin
          I don't think that this works because this is blocking and then the eventloop will never get to signaling for readyRead().

          I'm going to try to put the socket communication (it's single socket client side) into a seperate thread.

          Thanks
          McL

          VRoninV 1 Reply Last reply
          0
          • McLionM McLion

            @VRonin
            I don't think that this works because this is blocking and then the eventloop will never get to signaling for readyRead().

            I'm going to try to put the socket communication (it's single socket client side) into a seperate thread.

            Thanks
            McL

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @McLion That was supposed to run on the server. Are client and server on the same thread?

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            McLionM 1 Reply Last reply
            0
            • VRoninV VRonin

              @McLion That was supposed to run on the server. Are client and server on the same thread?

              McLionM Offline
              McLionM Offline
              McLion
              wrote on last edited by
              #6

              @VRonin
              Server is on a different machine in the LAN and the software is not from me.
              I only implement the client side.

              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