Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    When using Multithreaded Server how can I constantly check for data sent from the server to the client?

    General and Desktop
    qtcpserver qnetwork qtcpsocket qthread multi client multithreads
    3
    6
    2349
    Loading More Posts
    • 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.
    • J
      Jakebrown05 last edited by

      I have a multi-threaded server which adds a new thread for every client that connects to the server.
      On the client Side I am trying to figure out the best way to constantly check for updated data from
      the server. I was thinking having a separate thread running on the client side that has a while(1) loop running constantly checking for new data written over the socket. Is this the correct way to do things with QT? Or should I do it using signals and Slots? I tried using those as well previously but it would not update unless the client sent something to the server first.

      The overall outcome I want is so that when one client sends information to the server all other clients are updated with the same information immediately. The server has a function that when it receives data it runs through a loop updating all the other clients. Just don't know how to do this with QT.

      Thanks in advance,

      Jake

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi and welcome to devnet,

        For a thread server example, have a look at the Threaded Fortune Server example.

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

        J 1 Reply Last reply Reply Quote 0
        • J
          Jakebrown05 @SGaist last edited by

          @SGaist Hey

          Thanks for the reply. I have been looking at that example. Im just not sure how the client side of things work though. My current server currently connects multiple clients but the problem is having the live update among all clients. Similar to that of a chat app where if one user says "Hello World" All other users on the server will receive the same message...

          Jake

          M 1 Reply Last reply Reply Quote 0
          • M
            mcosta @Jakebrown05 last edited by

            @Jakebrown05 The client connect to the server using a TCP socket (or SLL) and read on it when the server needs to send something

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            J 1 Reply Last reply Reply Quote 0
            • J
              Jakebrown05 @mcosta last edited by

              @mcosta Does it read automatically ? or Is there a function that is called when something is sent across the socket?

              1 Reply Last reply Reply Quote 0
              • M
                mcosta last edited by

                I suggest to use the readyRead() signal to be notified when some data arrive on the socket

                Once your problem is solved don't forget to:

                • Mark the thread as SOLVED using the Topic Tool menu
                • Vote up the answer(s) that helped you to solve the issue

                You can embed images using (http://imgur.com/) or (http://postimage.org/)

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post