What is the best fitted networking tool in Java for a multiplayer FPS?

Hi!

When I began thinking about an online mode in my FPS, I thought only about RMI but problems of latency may discourage me to use it (if you compare with RPC for example). I’m looking for a better solution. I wanted to put the model part on the server and the controllers and the the views on the clients of course. I’m looking at MINA, the Network Game Engine of Riven and CommanderKeith, UDP and TCP/IP sockets, project darkstar… I don’t know what is the best fitted solution for my project. Can you give me your point of view about this?

That’s a very interesting question!

For an FPS where the landscape is static and the player controls just one character and not vehicles or anything, probably the best way to do it is a custom solution where you send raw byte arrays over TCP which have info like:

world timeStamp
player position
player direction

and these can be sent whenever direction changes, as well as just for an update say 5 or 10 times a second. You’d also send a byte array with info when a player changes state such as picking up a gun.

But such custom methods are pretty hard to do in practice, since without sending the whole game world from the server to all clients, the clients inevitably get out of sync. This can happen just from floating point error. It’s also extremely hard to code a completely deterministic world where clients and server do exactly the same thing - AI, randomness, etc become pretty difficult. But, Kev Glass does it well in his games - MiniMotox uses a clever system similarish to what I described above (I think!)- but besides the racing trucks, the world is static.

The demo game I posted up (http://www.java-gaming.org/forums/index.php?topic=18019.msg141395#msg141395) has got a couple of neat features which allow you to forget about all of the sync’ing and byte-array construction of data. The whole world can be serialized and sent to all clients, and the world can be re-wound so the server can go back in time to apply a lagged client event. While the sample game worked pretty well (it ran for months on Riven’s internet server without any problems), the code is undocumented and it is not a pluggable frame work at all - you’ll have to start with the demo game and carefully graft your own code on which wouldn’t be the funnest thing. One day I’ll try and fix it up, for now I just want to use it.

Good luck with your project. Incorporating network play is pretty hard so don’t be discouraged if you find you need to completely re-design the way your game currently works.

[quote]“Network Game Engine of Riven and CommanderKeith”
[/quote]
There is not such thing (yet).

I’m in the process of wrapping NIO into something ‘usable for everybody’, but it’s far from done.

AFAIK, CommanderKeith uses MINA, and wraps it a bit to suit his needs. (He has lots of needs! ;))

TUER is planned to become far from static but as the model part is on the server, it is easy to keep synced for a client, it only gets the required data, not the whole world, only the data contained in the visible cells in the view point of the player. In the worst case, as the data often change and lots of them won’t be proxied, if the client gets temporarily out of sync, it is not a problem as it will get the right data later when the network is alright anew, only one version of the world is available on the server and shared. I won’t try to send only the differences between the old and the new world as it might cause deeper problems when the client is out of sync. As I wanted to use RMI, I tried to minimize the amount of data sent between the server and its clients, it will be useful whatever the solution I choose. I will have a look to what you did. What do you think about Project Darkstar?

The method Quake 3 uses is very elegent and robust, there is a good write up on it by Brian Hook:

http://trac.bookofhook.com/bookofhook/trac.cgi/wiki/Quake3Networking

Does someone know JRemoting?

You might have a look at JGN (JavaGameNetworking) to do the dirtywork. You might also look at the monkey engine forum where the author posts frequently.

Ok I know it (http://javagn.org/wiki) but I don’t use JME. Can I use it for my own engine??

JGN is engine agnostic.

I have looked in the doc of JGN, I don’t know where to start. Where can I find a very very simple example to start? A sort of “hello world” with JGN?

Is it possible to use JGN like RMI or is it a different approach?

Is it better to regroup the data that have to be sent when using JGN?

There’s a server-client chat program in the examples/tests somewhere which shows how it works.

Sunsett (Matt Hicks) will be glad to tell you what JGN is about, he’s friendly and is always available on the JGN forums (http://www.captiveimagination.com/forum/index.php?board=4.0).

I’ve used JGN in my network framework instead of MINA and they both worked very well (I’m currently using MINA since it’s rock-solid stable and seems to do pretty fancy thread-pooling which seems cool). Neither are like RMI however - RMI is completely different and you don’t want to use it. JGN and MINA are primarily for sending and receiving byte arrays through either TCP or UDP. Both try to pretend they send objects by disguising the API with calls like send(object), but they’re really just for sending byte array data.

JGN has some other features as I understand which might be handy (like code that can find out the time difference between the server and client clocks).

Maybe what you should think about is how you want to take lag into account in your game, and how you are going to turn your game objects into byte arrays, and then turn those byte arrays back into objects, because those apsects will be the most difficult problems.

Sorry for taking so long to see this. Was at JavaOne and had a pretty busy week. :slight_smile:

The wiki is somewhat limited in what information is available there as it’s almost entirely community driven. However, as CommanderKeith explained there are tons of examples in the “test” package in the JGN source code. I would recommend checking it out from SVN and giving it a shot. Though CommanderKeith is correct on one hand that it is very different from RMI, there is actually functionality within JGN if you want to create something similar to RMI. It’s called RemoteObject. Similar to RMI you create an interface and implementation. The implementation gets registered on the machine you want to do the work and the interface gets passed to the RemoteObjectManager on the remote machine. This will give you back a proxy instance of the object and when you invoke methods on the instance they will be remotely invoked and give you the return value locally.

See this:

http://svn.javagn.org/core/trunk/src/com/captiveimagination/jgn/test/ro/TestRemoteObject.java

Here is an extremely simple example using JGN:

http://svn.javagn.org/core/trunk/src/com/captiveimagination/jgn/test/basic/TestMessageServer.java

There is a ton of other functionality in JGN and you can even just browse the SVN repository if you want to see that before you actually check it out.

Ok, “RemoteObject” is a fine name as when I read this, I thought about something similar with “Remote” in RMI. For the deployment through Java Webstart, do you think that I should sign the JAR of JGN by myself or is it already done?

As a first step, I will clean my source code in order to strictly respect MVC and then I will begin handling networking. I don’t want to rewrite all my game to add a multiplayer mode, I want to modify only the controllers, nothing else.

Is JGN stable? Some people on the web criticized it, they said it is developed only by one man. I hope this API won’t be forgiven.

No, the JAR is not signed so you’ll need to do that yourself. For all of my projects I create my own certificates anyway…do you see a benefit of JGN having its own?

Well, it is primarily developed by one person…me. However, there are other contributors to the project, they primarily just do updates as needed while they are developing their own games. Also, as others have stated, I do pretty well to keep up with people in the forums and I welcome the possibility of adding additional developers after they’ve proved their competence as a developer and have spent some time with JGN.

If you’re looking to synchronize positional information of objects in your game you should take a look at the synchronization system. It can be easily customized to work with any game engine (2D, 3D, Physics, etc.). Out of the box it supports GTGE, jME, jME-Physics, and Swing but it’s maybe ten lines of code to writing your own.

If you signed and you certified your JAR for JGN, it might be better. I will use the same certificate for my own JAR and this one so that the user won’t have to confirm once more…

Ok you reassure me.

I hope you’re right as (no way!) I don’t want to rewrite all to fit into a networking API. Maybe it is too early to choose a networking solution. Jeffrey Kesselman says that Project Darkstar may fit into my needs. Therefore, I will compare the both solutions.

I wouldn’t think it a good idea to make my certificate available for anyone to use as that would really violate the purpose of the certificate. I mean, people decide they trust my certificate for JGN and accept it. If anyone could use it they could sign their application which the user may not trust, but it then is automatically trusted. Also, other APIs like jME come with their own certificate as well…it just seems less complicate to let everyone sign their own JARs.

You can see an example usage of synchronization (using jME graphical synchronizer) using the jME FlagRush tutorial here:

http://svn.javagn.org/synchronization/jme-networking/trunk/src/com/captiveimagination/jmenet/flagrush/

Though the majority of code there is specific to jME if you look at the networking code you’ll see how few lines of code it takes to set it up.

For the moment, I’m going to use RMI even though I fear it will be slow. If JGN is abandoned, nobody will help me using it…

RMI is horrible for a FPS.

Don’t waste time on it.

It also has this distributed GC, which WILL periodically pause your game very noticably.

What makes you think JGN is abandoned? Many people use it actively…and since I’m the creator and sustainer of the project, I say it is far from dead. :wink:

At work, we succeeded in reducing the length of this pause to something “acceptable”.

I have seen only 3 games using it on your website.

I will invest only a very little time to make a blueprint using RMI. If it is really horrible even though I make some efforts to limit the number of RMI calls, then I will look at JGN.