I've a server/client arcitecture implemented, where all state changes are sent to the function, validated and broadcasted to all clients connected. This works rather well, but the system does not maintain syncrynization between the client instances of the game as of now.
If there happened to be a 5 second lag between the server and a particular client then he would recieve the state change 5 seconds after the rest of the clients thus leaving him with game state out of sync. I've been searching for various ways to implement a syncronization system between the clients but haven't found much so far.
I'm new to network programming, and not so naive to think that I can invent a working system myself without dedicating a severe amount of time to it. The ideas I've been having, however, is to keep some kind of time system, so each state change would be connected to a specific timestamp in the game. That way when a client recieved a state change, it would know exactly in which period of the game the changed happened, and would in turn be able to corrolate for the lag. The problem with this method is that in those n seconds lag the game would have had continued on the client side, and thus the client would have to rollback in time to update for the state change which definitely would get messy.
So I'm looking for papers discussion the subjects or algorithms that solves it. Perhaps my whole design of how the multiplayer system works is flawed, in the sense that a client's game instance shouldn't update unless notion is recieved from the server? Right now the clients just update themselves in their game loop assuming that any states haven't changed.