RMI or Sockets for networked game

I am looking into possible solutions to a networked game i am working on. My first thought was sockets with message objects, but the giant strings of if statements that are necessary for this approach is putting me off. So I was looking at RMI, which seems to let you call methods on a remote machine as if they were declared on you local machine. (correct me if I am wrong) Which, on the surface, looks awesome… but there has to be a reason it isn’t widely used for games. So what do you think, is RMI feasible for networked games, and if so do you care to give me a quick run through on how it works?

http://code.google.com/p/kryonet/
:slight_smile:

Java’s RMI should not be used for realtime I/O. It has many design flaws, and the only advantage of it is that it’s shipped with the JRE. If anything, avoid it and use (something like) Kryonet.

Just create a map of message types and handlers, look up the registered handler for each incoming message and call it.

KryoNet has a simple RMI system. It was written mostly just to see how simple it could be done (~441 lines using the CLOC tool). In practice, I still wouldn’t bother with RMI as having some method calls go over the network is just too much magic for me. It also has some very minor overhead. The alternative really isn’t a big deal, which is to explicitly send and receive messages (objects with KryoNet).

The biggest problem of RMI is that every ‘remote call’ will block until it received a response from the server: the return value or a remote exception. This means that the maximum messages / second is not determined by your bandwidth, but by the latency of the network.

The second biggest problem of RMI is the distributed garbage collector. RMI will cause full GC’s every once in a while, likely to cause hickups in your game.

That’s interesting, does that apply to the server and/or client side?

both

In addition to the quite excellent reasons already enumerated, by using RMI you pretty much limit yourself to a Java client for your game which may or may not be a problem for you. I generally avoid using RMI at all costs for any purpose :slight_smile:

Well thank you all for the insight. I had never heard of RMI before now, and I knew there had to be a reason why. You have all saved me the trouble of finding out myself! :slight_smile: I really like kryonet, I was going over the java docs and it is brilliant! I will probably use it in every game I make from now on!