jME3 Headless Server

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.

Client Code

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();
}

Headless Server Code

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);
}

Although all input/output is ignored, the server does keep game state and does call the simpleUpdate() as expected.

Next steps

Okay, so you can now start your game in a headless 'server mode', where to go from here?

intermediate, server, spidermonkey, headless, network, documentation

view online version