This time I'm not sure where I will end and what the result will be, but anyway I want to write this article about Game Servers, as well for my self having it documented somewhere. I will shortly describe how to use Zay ES net to implement your own very simply game server. As a base I took the sample from Paul Speed. The sample will be extremly simple and just to the point. I removed every distracting stuff. After having a starting point I will evolve it a bit to show it's coolness.
At your service
I will start with the code
First we create a jME server where we handover a name, a version, the tcp port and the udp port, nothing special.
And then we bind the entity data to the network.
To be able to send Postion.class and Model.class over the wire we need to register a serializer for them.
For simplicity we hold the game logic in a separated object which we will explore later. We just instantiate it here and call update of that game logic object in the loop. As well we start the server as you can see.
The game loop is running as infinit loop in a try catch block to be able to cleanly react if the loop internals throw an exception for some reason, at least the code try its best to clean up nicely and let the clients know the server is closing. So this try catch is a good practics.
We update the game logic and send the update to the clients 10 times per second. Normally the game logic is updated 60 times per second and the updates are send 20 times per second or less depends on the game you write.
Why you may ask, do the game logic run at different and faster rate as the updates we send, why not both with a lower update rate then. The answer is your game logic may update often so that physics is accurate and AI is self-responsive and so on. Not all updates are neccessarily entity updates as this may be to slow and clumbsy for various aspects of your game, but this is not part of this article though.