Shared session between users with web sockets

Hi everybody,

What I’m trying to do:
I am trying to build an anvil app for a physics simulation, which enables two or three users to connect to a “shared session”, meaning that e.g. two people enter the same code to an anvil start page, which puts them together in a session and enables them to exchange data just between them. For the data exchange the first person starts by sending some data and as soon as the other on receives and processes the data, he can react to that by also sending data back and so on. The data could be just strings or numbers for example.

What I’ve tried and what’s not working:
I’ve tried to implement websockets to handle the problem but it did not work out (e.g. the socket module on client side was a problem). Also I was a bit puzzled if it would work out in general this way since each user gets its own copy of the anvil app, so I am not sure how I could get a connection like client1-server-client2 implemented. Besides, I thought about assigning two users with the same session code a shared database but for my app it is crucial that the data can just be exchanged when the other client reacted (so their actions need to happen alternately if that makes sense to you) and I am not sure how to handle it this way.

So my question is: Is there a possibility to achieve a client1-server-client2 connection between two users to assign them to a session to alternately exchange data between them?

Thanks already in advance for taking the time to answer!

You can search the forum for chart or messaging applications.

If 2 seconds delay is acceptable, the easiest way is to use a timer and poll the server every second to check for updates from other users.

Another suggestion would be to use Firebase’s realtime listeners to achieve that goal. @mark.breuss’ firebase integration with anvil would help with that: