When adding multiplayer to your game, you may find that your server needs to know about game state (e.g. where are players, objects? Was that a direct hit? etc.) You can code all this up yourself, but there's an easier way.
It's very easy to change your current (client) game to function as a server as well.
First, let's take a look at the default way of creating a new game (in its simplest form):
public static void main(String[] args) { Application app = new Main(); app.start(); }
Now, with a simple change you can start your game in Headless mode. This means that all input and audio/visual output will be ignored. That's a good thing for a server.
import com.jme3.system.JmeContext; import com.jme3.system.JmeContext.Type; public static void main(String[] args) { Application app = new Main(); app.start(JmeContext.Type.Headless); }
simpleUpdate()
as expected.Okay, so you can now start your game in a headless 'server mode', where to go from here?
String[] args
from the main
-method to enable server mode on demand (e.g. start your server like java -jar mygame.jar –server
.if (servermode)
-block) (or if (!servermode)
for the client).