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
QtWS25 Last Chance

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.
  • M Offline
    M Offline
    McLion
    wrote on 30 Jun 2016, 13:31 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
    • H Offline
      H Offline
      Hamed.Masafi
      wrote on 30 Jun 2016, 14:16 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
      • V Offline
        V Offline
        VRonin
        wrote on 30 Jun 2016, 15:10 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

        M 1 Reply Last reply 30 Jun 2016, 15:14
        0
        • V VRonin
          30 Jun 2016, 15:10

          You can use waitForBytesWritten() at every cycle

          M Offline
          M Offline
          McLion
          wrote on 30 Jun 2016, 15:14 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

          V 1 Reply Last reply 30 Jun 2016, 15:33
          0
          • M McLion
            30 Jun 2016, 15:14

            @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

            V Offline
            V Offline
            VRonin
            wrote on 30 Jun 2016, 15:33 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

            M 1 Reply Last reply 30 Jun 2016, 15:35
            0
            • V VRonin
              30 Jun 2016, 15:33

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

              M Offline
              M Offline
              McLion
              wrote on 30 Jun 2016, 15:35 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

              4/6

              30 Jun 2016, 15:14

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved