Zay-ES-Net super-basic example

I’ve just created about the most basic Zay-ES networking example possible. Thanks to the ability to do proper gradle projects now with all of these nice public artifacts, it was really simple to setup.

It can be found here with documentation and everything:

Documentation = scroll down for the README.md

By “super basic”, I mean it. It’s just two command line apps and no user interaction. The server moves entities around on its own and the client can see the updates.

I should start tagging these “I just worked a bunch for you guys” with my “buy me a donut” link :slight_smile: Patreon

5 Likes

As I proposed: I would like to make a case study out of it except you sre against or want to do it your self

It would be fine.

Out of curiosity for an actual application, would you recommend having the server run in a similar way as your toy example as opposed to making it a headless version of an application with AppStates etc…?

I never run headless app states or any of that stuff. It has 70% that’s just rendering cruft that is never used.

I generally launch my own game loop thread… and I either just have a command line or swing GUI (that really just wraps the command line.)

I’ve started to ‘codify’ some of this in my SiO2 library as a GameSystemManager and GameLoop thread.

Much more lightweight than what a headless JME app provides and none of the baggage.

My servers only depend on jme3-core for jme3.math.

I started with the server and have set up everything. When I start I have

Exception in thread "main" java.lang.RuntimeException: Registration error: no-argument constructor not found on:class gameserver.Position
    at com.jme3.network.serializing.serializers.FieldSerializer.checkClass(FieldSerializer.java:57)
    at com.jme3.network.serializing.serializers.FieldSerializer.initialize(FieldSerializer.java:63)
    at com.jme3.network.serializing.Serializer.registerClassForId(Serializer.java:205)
    at com.jme3.network.serializing.Serializer.registerClass(Serializer.java:303)
    at gameserver.GameServer.main(GameServer.java:53)
Java Result: 1

So I looked at Position and there is a no-argument constructor but it is protected. When I change that to public the server starts. Can you maybe tell me what exactly I do wrong? I do not have much experience with java nor do I have an idea why this is protected? Shed some lights for me?

You are running against an older version of JME.

yes still alpha 1, after that SDK discussion I need now extra courage to upgrade to be honest :wink:

Then you are trying to run my stuff in the SDK instead of following the directions?

Alpha 2 is the future. Alpha 1 had bugs.

Ok. Yes of course, I have not the slightest clue how to do it without that SDK… But I guess I just can replace the core with the current one and still use the SDK. Without I’m lost.

Cant wait to see it! thanks for the advice

If you have seen my resources thread I started, I was not able to get zay-es-net working until alpha2 was out. I am new to java too and gradle still a little confusing to me, but for now I just have all the jme jars locally until I have more understandeng of gradle and there are more templates.

Yes, just swap the dependencies in your project.

However, the next time you try something and say it doesn’t work… it might be good to include that you ignored the directions and did it a completely different way. :smile:

The example is self-contained precisely to remove all such variables.

Right from the docs:

So, if that doesn’t work… I’m really interested.

If the “I did it a different way” doesn’t work… then that’s also interesting but for a completely different set of reasons and the approach to solving them is different. Fortunately, this time I knew exactly what was wrong.

1 Like

The problem is, that I was not aware of that. I just took your Java classes and put it into a basic Java application type project. So I do not exactly understand what directions you mean. Or was it to use that gradle things? Do you guys want to tell me that I can trash that SDK? And use what in return? vim? eclipse?

You might see, lost is not word like I feel now :wink:
EDIT: Of course I’m willing to learn, but then I need a few pointers which are not too vague.

I’m not saying that you can’t use the SDK. Of course it will work there too if you use the right dependencies.

I’m just saying it would be helpful to know in the future if the ‘exact instructions for running’ were skipped in favor of the ‘more advanced’ approach of rolling your own SDK projects.

Note: I spent a considerable amount of time making sure that this example would work ‘out of the box’ with no other stuff but Java installed.

Sorry if I kicked an investigation on your side. I wanted a copy and paste example and played that. So if I come up with other problems, then because I do it my way. And I like your example, simple and plain. Maybe for a case study I will make something in 3D. So maybe I’ll ask more stupid questions :smile:

I do not really know where I can change the dependencies nor do I know/understand to what I would have to change it, but I guess I will find out, maybe there is already a howto as a wiki and/or thread …

In your project… there is a part of the tree to open that shows all of the things you depend on. You can remove some things and add others, jars, whatever. Up to you. Normally I’d just snap a screen shot but I haven’t run the SDK in over a week and it is glorious.

I was thinking about what you said earlier, If you want your client to also run the logic of the game at times (for networking reasons or an offline mode) and your client does use AppStates etc… How would you avoid having 2 versions of the same logic classes: a server non-AppState version of logic classes and a client AppState version.

I have an app state that runs the game loop… called… GameLoopAppState. :smile:

Easy to make an app state call non-JME code. Hard to make non-JME code avoid unnecessary dependencies if it’s an app state.

Edit: and actually, you avoid a lot of ‘this works on the client but not in multiplayer’ issues if you still run your game loop as a separate thread even in single player. In my case, my GameLoopAppState is just managing the GameLoop thread.

Edit2: see: SiO2/GameLoop.java at master · Simsilica/SiO2 · GitHub

Just want to let you know: That works with jME 3.1 alpha 2 :smile: I just took the new core and networking jar and done. I’m thinking now for a sampel where you really can see something and not only System.out.println’s… Then I make the case study.