A fork of KryoNet, a Java library that provides a clean and simple API for efficient network communication.
This fork was specifically made for ProjektGG but also adds the most demanded features on KryoNet's issue tracker. If you have a pull request for KryoNet also consider adding it here, as KryoNet doesn't seem to be actively maintained anymore.
- Kryo 5.0.0-RC1 is used for the serialization (for a list of changes and new features see here; takes care of #77 and #123)
- A TypeListener for easier message handling (see the example below; also fixes #130)
- Listener is now an interface (#39)
- Includes a fix for the common Android 5.0 crash (#106, #120)
- The LAN Host Discovery is now available to Non-Kryo-Serializations (#127)
- Serializers are now created by factories (see the respective paragraph below)
- Kryonet now uses a gradle build setup
- Java 8 is supported
- Various improvements to the documentation (also takes care of #35, #44, #124)
The type listener takes care of distributing received messages to previously specified handlers. Especially with lambdas this allows for rather concise code: In the following example con is the connection to the client and msg is the received object - already cast to the right type:
TypeListener typeListener = new TypeListener();
// add a type handler for SomeRequest.class
typeListener.addTypeHandler(SomeRequest.class,
(con, msg) -> {
System.out.println(msg.getSomeData());
});
// add another one for SomeOtherRequest.class
typeListener.addTypeHandler(SomeOtherRequest.class,
(con, msg) -> {
con.sendTCP(new SomeResponse());
});
server.addListener(typeListener);
- The serialization objects are now created by factories:
SerializationFactory#newInstance(Connection)
- The in-built serializations still behave exactly the same (i.e. one serialization instance is used for the server)
- Custom serializations on the other hand can now decide to only get used once per TCP connection (all UDP connections still use one instance). This allows the server to keep responding while a message for another connection is still being serialized (see #137).
The download is available on the releases page. You can also use jitpack.io.
An example for gradle:
allprojects {
repositories {
// ...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.crykn:kryonet:2.22.3'
}