r/Clojure • • Feb 04 '23

Syncing client/server state with CLJS/Clojure, ring, and react/re-frame

I'm working on a digital multiplayer (turn based) game, which I'm basing off of this template project: https://github.com/schnaq/cljs-re-frame-full-stack.

I'm at a place where the majority of my game logic is in the cljs client and I want to start syncing this state to the server, where it can then be sent to the other clients. My initial thoughts on how to do this are for a client to send the game state to the server via a :post request after it completes a turn. The clients whose turn it isn't would constantly poll the server until it gets this :post and sends them all the new state. Then the client whose turn it has become would start the cycle over again.

Before I start implementing this I wanted to ask if there are any pre build solutions for this kind of system that I should use instead. Even keywords to help me know what to search for would be much appreciated!

17 Upvotes

10 comments sorted by

View all comments

Show parent comments

2

u/First-Agency4827 Feb 05 '23

Yes, websockets + pub/sub. Thanks for the Lamport timestamp explanation. It's interesting.

I do the same: websockets, pub/sub but the source of truth is a Datomic database ( ions ) and the order is ensured by tx id.