I'm attempting to develop a multi-platform turn-based game that [I suspect] follows the general client-server pattern. For this question, let's assume I only care about communications inside of a "battle" right now.
Here are the relevant mechanics of a battle: there are some number of "soldiers" in each battle. Each soldier is under the control of a player and a player may be in control of multiple soldiers in a given battle. Each turn only 1 soldier makes an action, the server will contain logic to determine which soldier that is. There are no time limits on turns. The player in control of that soldier select an action for that soldier which is sent to the server. The server will then determine the result of that action and send that information to every client.
This diagram can hopefully show my intended flow of information:
With each communication to client I was expecting to send a json of a ClientBattle object that holds all the data a client needs. On communications to the server, I was expecting to send a json of an Action object that contains all the info the server needs to calculate the outcome and advance the battle.
Unfortunately, I'm not quite sure how I would go about implementing this.
An approach that I would know how to implement that mimics this behavior would be to have each client HTTP GET a turn number from the server at a regular interval of ~3 seconds. If the turn number matches the client's data it does nothing until asking the server again in 3 seconds. If the number doesn't match, then the client HTTP GETs new battle data from the server and uses that to update its display. On client to server communication I'd send a HTTP POST request.
How would I clean this up - or - how could I implement it as in the diagram?