When using Multithreaded Server how can I constantly check for data sent from the server to the client?
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,
Hi and welcome to devnet,
For a thread server example, have a look at the Threaded Fortune Server example.
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...
@Jakebrown05 The client connect to the server using a TCP socket (or SLL) and read on it when the server needs to send something
@mcosta Does it read automatically ? or Is there a function that is called when something is sent across the socket?
I suggest to use the
readyRead()signal to be notified when some data arrive on the socket