Currently I am playing around with Vertx and Websockets for a new project I will be starting soon. A matching server, game server of sorts. Now this question might not be a very specific Vertx question but I figured I might as well ask it here too.
I have already set up my websocket server and all is going well. What I am researching now is Websocket synchronisation. More specifically make sure that when, if there are 4 clients for example, client A sends a message to the server, the server then dispatches the messages to all 4 clients at the same time. Goal is that the clients also receive it at same time so there is synchronisation, making sure that client C is not 10 messages behind still. Of course this would create client side lag if one of the clients is way behind and has slow connection.
Now yesterday I found an interesting article on how to Sync Multiple Clients
here. What it basically does is before the server dispatches the message to all clients, the server first does a ping/pong with all the clients and then sends the message. Now to me this sounds like a good way to do it for a single message, while the clients are basically idle. However when you are in the midst of a game and the client is already sending messages all over the place (streamed player position updates etc), I do not think this has any effect. Of course I could be wrong.
What I cant wrap my head around is if I actually need something like this in the first place. When the client A message arrives on the server and I hit the websocket handler, I can send the same message to all connected clients. At that time the server sends the messages at the same time. Obviously ignoring client connection speed.
websocket.handler(input -> {
for(ServerWebSocket client: m_clients.values())
{
client.writeFinalTextFrame(input.toString());
}
});
There is very little information out there on this topic so it makes me wonder if it even is a problem I should be worrying about. Pure theory wise I could do something like stop all sending of stream messages (put in buffer/queue) when a synchronized message has arrived from a client, let the server do a ping/pong to all clients to check if they have processed all messages, send the message and continue with whatever messages are now stored in the buffer. But it sounds for lag waiting to happen. Also after the ping/pong, if for example client C has a slow connection again, the client will receive this synchronized message too late again... defeating all the purpose.
Anyone has some experience with this or some feedback.
It would be gladly appreciated.
My apologies if this doesn't belong here 100%.