Advertisement

Is Java Socket the best option for a real time game server?

Started by November 23, 2013 12:00 AM
5 comments, last by lbroussal 10 years, 11 months ago

Alright, so to start off I am currently using the native Java Socket implementation and everything works fine. I'm planning on rewriting the networking portion of the game engine to improve and clean it up and I'm not sure if I should move to another API or not.

From what I've read, my options are:
Native Java Socket

Java Fast Socket

RMI

The game engine in question is 3d, with an aim of 2 - 24 players on a server at a time. I use floats for location/velocity/rotation updates.

What would be the best option? Latency and stability are extremely important. No one likes lag and random disconnects. tongue.png

Also, there is an API I saw a while back that was an optimized network packet API for Java. I can't remember the name unfortunately... Anyone know what it was called?

-edit-

And of course, I immediately find some good anwsers after I post this thread.

Looks like I should use Kryonet which is designed for this kind of thing, or I should build my own thing off of Java NIO.

RMI is not tuned for game needs, and would probably be a poor choice.

Java sockets with Java nio / aio support would probably perform well, although they are known to be tricky to get to work right.

I know nothing about the Java Fast Socket library.

enum Bool { True, False, FileNotFound };
Advertisement

RMI is not tuned for game needs, and would probably be a poor choice.

Java sockets with Java nio / aio support would probably perform well, although they are known to be tricky to get to work right.

I know nothing about the Java Fast Socket library.

Yeah, I used Native Java Socket originally and it worked but it was very finicky and sometimes it would refuse to connect for unknown reasons. KryoNet so far has been very good. It was a little annoying to build the jar for it and get all the build paths set up but it's so easy to use and it's very stable. It's great. I'd recommend it to anyone who needs a fast and simple Server/Client set up.

Humm,

the Java 'native' ( plain sockets? ) are a good api... btw.. its blocking....

The big problem is you must have a unique thread for each socket connection ( or it may block for reading purposes ) plus a thread for the "ServerSocket" ( the socket to accept connections, the 'bind one' )....

The NIO api is more indicated to high amount of connections because its non blocking ( you may use channels, selectors, etc )... and, maybe you may consider using UDP/Multicast if you game is intended to scale up...

The NIO is very powerfull, btw its hard to master ( as hplus0603 said before ).

I dont know so much about this Kryonet or Java Fast socket.

Well... sometime ago ( humm about.. 6~8 years ago) I wrote a little library to learn/try about java sockets... it was very fun to code it... if you want to try and explore the code... fell free to download and ask me if you have some doubts.... ( https://sourceforge.net/projects/mmooog/ )

it use multi-threaded approach and the plain java sockets....

( well.. some comments are in portuguese, but the most part was commented in english )..

KrinosX

Using RMI in a game is a horrible idea. First off its like "please, everyone feel free to come hack the hell out of my game I worked so hard on" and you don't want that. And 2 it can be a little slower then just sending bytes.

I am using kryonet now on my Java multiplayer game and its phenomenal, you can take a look on my channel, its the newest videos: http://www.youtube.com/user/baseball4355

Kryonet is very easy to use and setup and takes out all of the ugly looking network code for you. Why remake the wheel if its already presented to you

Using RMI in a game is a horrible idea. First off its like "please, everyone feel free to come hack the hell out of my game I worked so hard on" and you don't want that. And 2 it can be a little slower then just sending bytes.

I am using kryonet now on my Java multiplayer game and its phenomenal, you can take a look on my channel, its the newest videos: http://www.youtube.com/user/baseball4355

Kryonet is very easy to use and setup and takes out all of the ugly looking network code for you. Why remake the wheel if its already presented to you

Yeah I implemented KryoNet into my engine a couple of weeks ago. It's great. It's much easier to work with than Java Socket.

Advertisement
Hi,

This is now a common problem solved you should not worry anymore with by using existing solutions.
With Nuggeta (http://www.nuggeta.com) our nio low latency solution you even don't have to worry about bandwidth and data representation.

This topic is closed to new replies.

Advertisement