How to use websockets in a real-time multiplayer game?

1.6k Views Asked by At

I got inspired by a game called agar.io to try to make my own browser game using websockets. I wonder what the best way of starting with this. I have some experience in making multiplayer games, but no experience with websockets.

I know about socket.io, but do not really want to write this in javascript. I tried out this library: https://github.com/mrniko/netty-socketio which is a port of socket.io to java, but got delays when i ran the demo(50ms on local computer)

I looked into LibGDX and found this library (https://github.com/pepedeab/libGDX-Net), which i am thinking right now is the best way to go.

Anyone got some tips, hints or suggestions?

1

There are 1 best solutions below

2
On BEST ANSWER

Libgdx is where you should start. Not many people are working with Libgdx browser deployment (let alone a networked libgdx GWT application) I have found, but I'll share some insights with you.

Be mindful that in browser deployment you have much more restrictions on the functionality of your application. Since you would be using (Libgdx) GWT to deploy your application, every single one of your external jars must be GWT compatible in order for them to be deployed (kind of a setback). So, if you are sure you want to get into browser deployment, definitely expect some headaches and possibly some obscure workarounds. See http://www.gwtproject.org/doc/latest/RefJreEmulation.html

For some networking code examples, check which websocket library to use. I know there are some android examples but they reference some GWT compatible websocket stuff that you're potentially looking for.

If you are looking for a cleaner way of doing things, Nathan Sweet and the people at Esoteric Software have done an incredible job with Kryonet (a networking library) that is HIGHLY recommended if you wanted to take the less headache route and switch to desktop/android/iOS