I am currently writing a 2D top-down shooting multiplayer game using Java. I have a game loop at the client-side that does the following in order in each game tick (The client is running in a tick rate of 60 t/s):
client_gameloop{
1. Send an input sample (an object storing info about what keys are pressed)
to the server through a DatagramSocket
2. Receive info on change in game state from the server
3. Update the client-side game state through the received info
}
For the server-side, I have a game loop that does the following in order in each game tick (The server is running in a tick rate of 60 t/s):
server_gameloop {
1. Read an input sample through a single DatagramSocket
2. Using the input sample to apply physics to the game world and update the game state
}
When I try to connect the first client to the server, the game flows fluently with unnoticeable delay. However, when I try to connect the second client, both first and second client start to lag behind the server greatly (delay ranges from 5s to 10s). I am currently stuck on what causes the delay. Am I handling the sending and receiving of info between client and server in a wrong way that causes game state in the server-side not being able to synchronize with those of clients'?