Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the most efficient Java implementation for a real time game server?

I'm planning on building a Java server that will handle real time game communications between clients. What is the best type of Java implementation out there that could efficiently and, hopefully, accurately communicate between a client and server at high speeds (say 5-15 packets per second)? I know there are many types of Java networking APIs (ie. ObjectInputStream and ObjectOutputStream, DatagramPacket, KyroNet, etc.), but I'm not sure what is the most effective and/or commonly used implementation for such a scenario. I would assume that most real time games use UDP communication methods, but I understand the reliability issues that come with it. Are there UDP implementations that have some form of flow control? Anyway, thanks in advance!

like image 868
Brian Avatar asked May 09 '11 22:05

Brian


2 Answers

A few things to consider:

  • Java NIO is really good, and can handle the kind of throughput/latency you are looking for. Don't use any of the older networking / serialization frameworks and APIs
  • Latency is really important. You basically want a minimal layer over NIO that allows you to send very fast, small, inidividual messages with minimal overhead.
  • Depending on the game, you may want TCP or UDP or both. Use TCP for important messages, UDP for messages that aren't strictly necessary for the game to proceed or will be subsumed by a future update (e.g. position updates in a FPS)
  • Some people implement their own TCP-like messaging protocol over UDP for real time games. This is probably more hassle than it's worth, but be aware of it as an option if you really need to optimise for a specific type of communication
  • For real time games, you are nearly always doing custom serialisation (e.g. only sending deltas rather than full updates of object positions) - so make sure your framework allows this

Given this, I'd recommend one of the following

  • Kryonet - lightwieght, customisable, designed for this kind of purpose
  • Netty - slightly more enterprise-oriented, but very capable, robust and scalable
  • Roll-your-own based on NIO - tricky but possible if you want really fine grained control. I've done this before, but in retrospect I probably should have picked Kryonet or Netty

Good luck!

like image 106
mikera Avatar answered Sep 23 '22 00:09

mikera


Immidiately forget ObjectOutputStream and ObjectInputStream. These are the standard output-input mechanisms of the old standard java serialization, which is slow and produces bloat objects. Some resources to start with:

  • http://code.google.com/p/kryonet/
  • http://code.google.com/p/pyronet/
like image 45
gyorgyabraham Avatar answered Sep 25 '22 00:09

gyorgyabraham