Base JME Networking example

In local testing and prototyping, I find that I was creating the same patterns over and over again when building out a simple networking example. Recently, as part of getting SimEthereal ready for a more thorough release, I wanted to build an example application… partially as documentation and partially to use as a test base to fix one or two last niggling issues.

On the way there, this turns out to be a pretty good starter base that any new JME game could probably use as a cut-pasted initial code base. Given that, I’ve purposely left any game specific stuff out of it and given it a special tag in its current form. If it turns out to be useful and needs updates then I’ll create a branch from that tag… but for now the tag should suffice.

Here is where the code lives:

If you build it, you will also (currently) need the SNAPSHOT builds of Lemur and SiO2 because of yet-to-be-released bug fixes in those libraries.
Lemur GIT is here: GitHub - jMonkeyEngine-Contributions/Lemur: Lemur is a jMonkeyEngine-based UI toolkit.
SiO2 GIT is here: GitHub - Simsilica/SiO2: Base pack of useful reusable game code that can help bootstrap any JME game project.
In both cases, checkout the repo, run ‘gradle install’, and you should be good to go.

You can run sim-eth-basic by checking out the repo, going into the sim-eth-basic direcory, and running ‘gradle run’.

Edit: I went ahead and rolled an actual release for this: Release Network base code and example app bundle. · Simsilica/Examples · GitHub
From there you can even download the app and try it:

What You Get

This is an application with a main menu that allows you to either host a game with some particular settings or connect to an existing game.

There is a “Hosting” screen that allows the hoster to join or leave but could be expanded with other hosting setting as the game might need.

There is a login screen that currently just accepts a player name but could be expanded.

There is an in-game menu that pops up once connected and has tab support for adding options, help, whatever. Currently it just allows the player to leave the session or close the game.

All of the menus and screens are wired together with appropriate app states and there are error popups and confirmation dialogs and so on. There is even a status message stream at the bottom of the screen for in-game messages. I’ve even included a DebugHudState that can easily be used to add dynamic debug content… though it’s currently not hooked up to a key toggle.

The basic networking setup code is in place managed by appropriate app states and so on. Hosting a game creates the server using a GameServer class and connecting to a game uses a GameClient class. These can be modified by the real game to add the services as needed. The GameServer uses SiO2’s game service manager class which is like a lightweight app-state manager that is not JME specific (and doesn’t have the 80% of other cruft that app states have that are unnecessary in the back end).

The UI uses Lemur so can be restyled just by using a different default style.

How Would I Use It

Get the sim-eth-basic directory in your favorite way then copy+paste the directory into your own.

Use your favorite IDE to refactor that package name to something that makes sense. Modify the build.gradle file to point to your new mainClassName

Edit the GameConstants class to have appropriate values for your game.

Edit MainMenuState to change the app name or modify the main menu as needed.

At that point you have a running networking app that just doesn’t do anything.

Add your own back-end services to GameServer. For things like game logic, physics, etc. do this with GameSystems added to the GameSystemManager. For custom network hosting things, add those to the SpiderMonkey Server services.

Add your own client-side services to GameClient’s internal Client.

Add your client app states as children to GameSessionState.

What is SiO2

SiO2 is a base utility library that includes some useful JME things and probably deserves its own post. I envision this kind of like Google’s Guava is for the rest of the Java world. These are useful utilities that almost every game will find useful, like:

com.simsilica.sim: GameSystem management code. This can be used to manage game services in a JME-agnostic way. You can either manage your GameSystem updates from an app state or there is a build in GameLoop background thread.

com.simsilica.sate: Useful app states including a CompositeAppState for managing a linked group of app states (like all of the states for a game session). It also has a DebugHudState for easily adding watches for dynamic values in various places on the screen.
com.simsilica.event: a really light weight event bus that can use traditional listeners or reflection delegates.

There are some other Zay-ES specific utility classes also. There is a compile time dependency on Zay-ES but you can exclude it from your games if you don’t use it.

In Conclusion

This package should make it easier to get started making a networked game. It doesn’t do the hard work for you and you still already have to know how to make a networked game… but this is the stuff I found myself repeating over and over again and sometimes not getting it quite right. Having a base will be nice to shorten all of those times by a couple days.

If there is interest in this, I will update it with a new tag when I’ve added the basic game communication (sending login info to the server, letting the client know they are ‘in’, sending player joined messages, etc.)

Some screen shots:

…and I’ll hide this at the bottom just in case: Patreon


If folks want, I can put together a prepackaged version of just the app just to see what it looks like… and/or a tarball of the source for anyone that just wants to use it as a base without checking it out.

It’s no frills because apps will most certainly want to add their own transition animations, styling, etc… But even still, I think it looks nice for having essentially no custom styling or anything.

Very interesting. Both example and SiO2. I will wait for new updates.

(Just sad I am too retarded and can’t overcome gradle)

I don’t know but could I (and other) give suggests about SiO2 library?

Sure. Though I’m pretty strict to keep it from too much feature-creep. Besides I already have other libraries for that. :slight_smile:

What did you have in mind?

Gradle is generally pretty easy so maybe it’s just something simple or a misunderstanding? Without going too far off the rails, I can offer some minimal tech support here.

I went ahead and rolled an actual release for this: Release Network base code and example app bundle. · Simsilica/Examples · GitHub
From there you can even download the app and try it:

1 Like

I tried to “gradle run” and get something like this. Maybe the mistake is too obvious but I don’t see it.

Well. Maybe something like easy access to decals. I saw Projective Texture Mapping there but I am not sure it works for 3.1b.
And your TreeLightning shader. I found it works well not only for trees but for every objects that could be affected by wind (like moving grass, looks very cool).

This would be a useful utility but probably not for SiO2. Maybe for SimFX which is another OSS library I have.

Cool. That one is already available in another library and not really the kind of thing I mean to include in SiO2.

re: your gradle errors, it looks like you didn’t check out and ‘gradle install’ the Lemur package mentioned above. Right now this code unfortunately relies on snapshot versions so they aren’t available in the public repos yet.

It turns out I didn’t understand idea of SiO2.

Ah. Thanks.

SiO2 = silicon dioxide = silca = sand. It’s also the logo for my company. :slight_smile: But by picking the base molecule like that… and also being ‘sand’… the idea is that this should be foundational code.

Basically, if there is a utility class that is likely to be useful to every game then it’s a candidate for inclusion here. Now, I’ve expanded that a bit to include Zay-ES based games because I kind of think all games should be ES based and Zay-ES is my favorite (I’m biased of course). :slight_smile:

Added the basic account service stuff and I was able to do it in one commit so it’s easy to see all that was required to add it:

And the last additions before I have to start getting into real game-specific type stuff and using SimEthereal… I added the minimum GameSession client/server services:

The visible part of this change is that players will see the joined/left messages on their on-screen info stream as players join and leave the game.


I will use them for my game networking part when ever times come. Right now I am digesting lemur and it is really easy to understand, use, expand it. Hope your other libraries also be like it.

Best Regards

1 Like

Great work, I might be able to make a networking game :wink:

Went ahead and made a ‘release’ of the base example with the simple account session and game session stuff added. As mentioned, this is kind of as far as one can go without getting game-specific… so it’s a good template to start from:


So the next time I post something (hopefully later tonight) it will be an actual game-like example:

I updated is so that players control physics (really simple physics) objects and the object updates are blasted over the network in the ‘naive’ way.

A picture of myself logged in from another client:

I’ve purposely been developing this without using Zay-ES to as not to confuse things but man it’s hard. Seeing all of the hard-coded dead ends is really frustrating when you’re used to better. Once I get Sim-Ethereal integrated, I’m going to fork this into an ES version. It will be easier to add things like space stations and stuff.

Anyway, the code is checked in… it’s sufficiently crappy and full of FIXMEs because this is not the way you should do networking. Tomorrow I’ll rip that out and replace it with SimEthereal… but at least now I can see that all of the ship controls are properly hooked up.


Awesome work =) thanks pspeed.

Inspired by No man’s sky? :wink:

Heheh… not really.

For a proper network test, I needed to show a bunch of 3D objects moving around. The only thing I could think of that had minimal assets would be if there were no level, no ground, no buildings, etc… ie: SPACE! :slight_smile:

I wanted the grid lines to show motion and to help people figure out where the zones start/stop when I get SimEthereal in place. Though I tweaked it to look cool. And since we’re in space, we need a sky box and I had one of those from earlier prototypes on other things.

No Man’s Sky inspires me to want to go back to terrain generation… since after playing NMS for X++ hours, I feel like I was on track to do a couple things better than they did. I didn’t have to contend with high altitude flight but I feel like that was a solvable problem. Then again, I also didn’t need to deal with the variation of many millions of worlds.

Edit: and for the space ship, I went to open game art and searched for 3D space and that was on the first page. I want to reskin it but finding a good asset and tweaking it are bottomless pits that ultimately have nothing to do with my goal here. :slight_smile:

If someone wants to improve it:

Created a NetworkNaive-v1 tag and uploaded a release:

So if you download:

…you can actually run the ‘game’ with the naive networking approach. If there is interest, I can even setup a public server for folks to try it. On localhost, it’s ok but it will be over the real internet where it’s real problems show up.

Now on to Sim-Ethereal integration!