Trying to learn how to display a value over a network but can't quite figure out how.



  • Let's say we have 2 QLCDNumber displays.

    1)TOTAL amount of say bicycles that is owned.

    1. AVAILABLE amount of bicycles that people can rent out.

    When I first open up the app i set the total amount of bicycles. The available amount then copies this and a person makes changes using plus and minus buttons to the available amount.

    Now lets imagine i have 2 shop computers on the same network. 1 is upstairs the other is downstairs.

    How can i get the QLCDNumber to display/change/update on each computer the app is open.

    EG upstairs computer deducts 1 from the total making the available one less. This is then immediately updated on the second computer using the app.

    Would i use Qwebsocket or would i need to create another app acting like a client server that stores the details with the app using those details to display and edit????


  • Moderators

    @MrCrackPotBuilder
    What are your requirements exactly? Is this system intended to scale? Meaning do you plan to add another computer at any time and it should also display the correct value?
    Or is a direct connection between those 2 computers sufficient?



  • Thanks for the reply. Hhhmmmm I would say that it would be a good idea to have it on more than one. All must be updated real time (with minimal lag of course).


  • Moderators

    @MrCrackPotBuilder
    then you should go via the server approach. Take the Fortune Server example as a starting point.

    In this example the client disconnects after receiving the fortune value from the server. In your case they must not of course.
    So for your case each client notifies the server whenever the value has been changed by the user. The server then sends out the new value to each client. The server stores a list of all connected clients (a list of QTcpSockets) and writes the new value to each socket -> each clients receives the updated value data and updates it's displayed value accordingly.

    This is the basic concept of the data transfer. Now its a good idea to specify the communication protocol -> the layout of the messages to send over your connections.
    For example it could be COMMAND|VALUE\n So each command ends with a \n as a delimiter, this makes it possible to know when you have received a full command. This layout can be anything you like though. The most important is that you specify a delimiter.
    Because a common pitfall for beginners is that they think when they send data on one side it is received as a whole block on the other side. But this isn't guaranteed and you might be notified multiple times that data on the socket is available. The delimiter helps you check if the data is "complete" yet and you are safe to process it.

    Note: The server has not to be a standalone machine. It could be launched on any client machine. So 1 machine can be server AND client. And the client on this machine connects to "itself".

    Hope this helps to give an overview and starting point.
    I suggest you check out some more QTcpServer examples.



  • If i make the app both client and server wouldn't that create issues with updating the dates or issues with which server takes priority ???


  • Moderators

    @MrCrackPotBuilder
    of course there should only be 1 server overall. Not every client should host also a server. I just mentioned it, to let you know that just because of the server/client architecture it's not necessary to run the (single) server on a dedicated machine. ONE of the client machines can run the server in parallel.



  • If you have a fixed number of servers >2 you can implement paxos to decide the state.

    even if you decide to go down the route of a single server you have to be careful how you handle corner cases. for example you only have 1 bike left and 2 clients send you a request for a bike at the same time


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.