I’ve set up my game as a server, and also created a client in a separate project. When I run my client, it automatically start up the server as well, so I assume the client is connecting to the server properly.
But when I start up the client, it’s just a black screen. I assume that’s because the client doesn’t know anything about the server’s rootNode. Do I need the server to send a message containing the rootNode (plus other important stuff) to the client to display? And if that’s the case, how do I get the client to use the “imported” rootNode instead of its default?
I’m not sure that attaching the server’s rootNode to the client’s rootNode would work very well, because the only way the can communicate updates is through messages.
As you will find, there are many wrong ways to build a server and client game, and very few correct ways. One of the largest invalid assumptions is that the server needs a jme application and scene graph.
There is no easy way to do what you want to do. But some options are harder than others.
The hard way is to build your own networking infrastructure and sync the client and server manually. For this you will need to implement some form of a component system.
The easy way is to use @pspeed’s SimEtheral component based network server/client library. It works out of the box, but you will still have to write your game around it.
There is no magic copy server root node to client root node. But SimEtheral is as close as you will get.
I personally took the hard way developed my own networking library based on netty.io, and my own component system, and my own networking component sync library. It has taken me over two year of development.
Unless you are willing to spend that much time on it, use SimEtheral.
It is nearly impossible for the server to sync the client every frame. At 60 fps, that is 16 ms per frame. Normal network latency is between 20ms to 50ms, and if servers are in other countries it is not uncommon to see up to 100ms. Thus several frames have gone by before the server could get a single message to the client.
Also, ‘syncing’ the client to the server IS done with messages. And a lot of technical code is required, such as interpolation between last position and current position, handling user input, and notifying the client of what world objects exist, which ones don’t exist, which ones moved, and interpolating to where they moved. Not to mention authentication for the user. Simply using java io is very limiting and will require massive amounts of code. Correct implementations of a networked system use nio and both udp/tcp.
As mentioned, SimEtheral will handle that for you to a large extent. Otherwise you are in for hundreds of thousands of lines of code that you will have to write.