I am making a Java game using Slick2D and using Kryonet for a multiplayer game. When a player presses W, A, S, or D, they move, and the PlayerMovePacket object is sent over the network (via UDP) to the server. The server then sends this to other clients who establish a local copy of this player’s position according to the information inside the package.
Here is the code for PlayerMovePacket:
public class PlayerMovePacket { public Vector2f pos; public int clientID; public PlayerMovePacket() { pos = new Vector2f(0, 0); clientID = -1; } public PlayerMovePacket(Vector2f v, int id) { pos = v; clientID = id; } }
By doing this, clients / server are overloaded from too many messages and fail. The only other option that I see is that I will send the player’s position only every few milliseconds. However, customers will not have the most recent player position most of the time, and movement will be erratic
Any ideas on how I can stop server overload?
source share