Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

877579 Posts in 32868 Topics- by 24310 Members - Latest Member: Muzuh

May 19, 2013, 10:23:33 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)UDP Network Libraries for Java
Pages: [1]
Print
Author Topic: UDP Network Libraries for Java  (Read 1523 times)
gnat
Level 1
*



View Profile WWW Email
« on: August 04, 2012, 08:36:32 AM »

Suggestions ? Please specify if you (or someone you know) has built a real time game with it or not.

Right now I'm considering:

1. http://code.google.com/p/kryonet/
2. A port of enet on github https://github.com/csm/java-enet ... not sure if it's usable? anyone?

I come from the world of C networking libs where they are abundant and great. I find Java lacking in this area. Minimal systems are best. I just need a UDP stream.
Logged

nc-cms - Open source, lightweight, and fast website content management for indies.
Woot Events - Gamer event listing site. LAN Parties, Game Jams, etc.
Liosan
Level 2
**


View Profile
« Reply #1 on: August 04, 2012, 09:59:27 AM »

What do you need from a library? Have you considered just using DatagramSocket?

Liosan
Logged

Chromanoid
Level 7
**



View Profile
« Reply #2 on: August 04, 2012, 10:05:48 AM »

The Java Standard Library has builtin networking. If you just want bytearrays, use the DatagramSocket or DatagramChannel: http://thushw.blogspot.de/2011/06/asynchronous-udp-server-using-java-nio.html

If you want more highlevel stuff try Apache Mina or JBoss Netty.
« Last Edit: August 04, 2012, 10:13:34 AM by Chromanoid » Logged
gnat
Level 1
*



View Profile WWW Email
« Reply #3 on: August 04, 2012, 11:26:00 AM »

I thought the JDK built-ins would be easy, but have either of you actually tried using DatagramSocket for a game? I'm trying and finding the built-in NIO libs to be extremely difficult to comprehend.

Not to mention most of the tutorials on the internet about NIO and DatagramSocket have conflicting information or are just wrong. I just spent the last hour with the tutorial Chromanoid posted and it does not output or do anything.
Logged

nc-cms - Open source, lightweight, and fast website content management for indies.
Woot Events - Gamer event listing site. LAN Parties, Game Jams, etc.
Chromanoid
Level 7
**



View Profile
« Reply #4 on: August 04, 2012, 01:23:28 PM »

Try Mina or Netty. There are several NIO libs that try to make it easier.
http://mina.apache.org/udp-tutorial.html

btw whats your problem with kryonet? It is very easy and lightweight.
Logged
gnat
Level 1
*



View Profile WWW Email
« Reply #5 on: August 06, 2012, 01:23:59 AM »

I spent the entire weekend figuring out how to do real-time UDP networking for games in Java and I will share my thoughts. Some things I learned:

  • Contrary to the popular assumption, real-time networking support (UDP) is something Java seriously lacks good solutions for.
  • The vast majority of people recommending Java networking libraries have never used them, and therefore don't realize they are bad.
  • Information regarding Java networking is extremely sparse, conflicting and incorrect at times.

Libraries I tried, and my thoughts:

DatagramSocket (import java.io.*) I/O JDK Library - Looks like exactly what you need until you use it and realize it's blocking, you need to thread it, AND you are required to have seperate ports for each client you want to connect. Wtf were they thinking?

DatagramChannel (import java.nio.*) New I/O JDK Library - Extremely unintuitive and over-engineered. Highly misleading naming conventions. ByteBuffers are ridiculously unintuitive to use and cause a lot of trouble. I eventually went with this solution after two full days of intense research, hair pulling and rigorous testing.

Kryonet- Makes extensive use of "javascript style" anonymous functions. Layers upon layers of abstraction, which means you will never have simple access to your networking resources.

Apache MINA and Netty 2- Too high level if you want any sort of fine grain over your networking that is all too useful for real time networked games, although not as over-engineered as Kyronet. Apache MINA is the successor to Netty as far as I know.

extasys - If I didn't end up nearly killing myself with NIO, I would have settled on extasys. Reasonable middle ground.

java-enet (jenet)- enet for C is great, and in theory, java-enet sounds good. However it is incomplete and realistically, nobody uses the enet Java version, so you're taking a huge risk building your project on it.

priobit- You're taking a huge risk building your project on this as it looks unmaintained.



Conclusion:

I can now see why there are not many multiplayer Java games. Java really needs just a basic, non-blocking UDP interface in the JDK, but it does not. Prepare to spend lots of time.
« Last Edit: August 06, 2012, 01:41:12 AM by gnat » Logged

nc-cms - Open source, lightweight, and fast website content management for indies.
Woot Events - Gamer event listing site. LAN Parties, Game Jams, etc.
Chromanoid
Level 7
**



View Profile
« Reply #6 on: August 06, 2012, 07:45:24 AM »

@Kryonet: What anonymous functions? It allows to expose objects and interfaces over network in a very simple and elegant way. It has very few LOC and is easy to understand.

NIO is indeed not that easy to use, but it is not that hard either.
http://code.google.com/p/kryonet/source/browse/trunk/kryonet/src/com/esotericsoftware/kryonet/UdpConnection.java is imo very concise.

Mina is not the successor of Netty.
Logged
gnat
Level 1
*



View Profile WWW Email
« Reply #7 on: August 10, 2012, 11:20:01 PM »

For anyone following this thread, beware that Java's System.out.println is SUPER EXPENSIVE and will absolutely kill your performance.

Be sure to disable your println's unless you're specifically doing debugging.

We just spent the last hour realizing this, and now we're running speedy.
Logged

nc-cms - Open source, lightweight, and fast website content management for indies.
Woot Events - Gamer event listing site. LAN Parties, Game Jams, etc.
Chromanoid
Level 7
**



View Profile
« Reply #8 on: August 11, 2012, 08:36:51 AM »

You might want to use java.util.logging. Also beware of String concatenation.
Logged
gnat
Level 1
*



View Profile WWW Email
« Reply #9 on: August 12, 2012, 01:47:50 PM »

For those following this that need serialization (aka the ability to send complex datatypes over the wire), we settled on: http://msgpack.org/

Very small serializations, fast, easy to use.

Finding a serialization library for our needs was also difficult... we tried many including the JDK built-in, Kryo and Google's protobuffers (not usable for real time multiplayer). Everything was serializing data far too large... we were extremely lucky to find MessagePack.
Logged

nc-cms - Open source, lightweight, and fast website content management for indies.
Woot Events - Gamer event listing site. LAN Parties, Game Jams, etc.
Chromanoid
Level 7
**



View Profile
« Reply #10 on: August 12, 2012, 10:52:25 PM »

cool find! never heard of it before. i always looked at this list: http://code.google.com/p/thrift-protobuf-compare/wiki/BenchmarkingV2
messagepack looks very nice for games.

hey they moved the wiki and have a msgpack test now: https://github.com/eishay/jvm-serializers/wiki/Staging-Results
« Last Edit: August 12, 2012, 11:01:21 PM by Chromanoid » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic