EsotericSoftware / kryonet

TCP/UDP client/server library for Java, based on Kryo
BSD 3-Clause "New" or "Revised" License
1.82k stars 417 forks source link

Learning kyro and java for school some problems.. #113

Open Kuutio opened 8 years ago

Kuutio commented 8 years ago

Im trying to make basic server whit kyro. Getting this weird error.

Exception in thread "main" java.lang.NoClassDefFoundError: org/objenesis/instantiator/ObjectInstantiator
    at com.esotericsoftware.kryonet.KryoSerialization.<init>(KryoSerialization.java:25)
    at com.esotericsoftware.kryonet.Server.<init>(Server.java:91)
    at com.esotericsoftware.kryonet.Server.<init>(Server.java:73)
    at server.GameServer.<init>(GameServer.java:24)
    at server.GameServer.main(GameServer.java:54)
Caused by: java.lang.ClassNotFoundException: org.objenesis.instantiator.ObjectInstantiator
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 5 more

quicktestcode.

package server;

import java.io.IOException;

import com.badlogic.gdx.ApplicationAdapter;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import server.SomeRequest;
import common.Network;

public class GameServer extends ApplicationAdapter {

    static int SERVER_TCP_PORT;
    static int SERVER_UDP_PORT;

    public GameServer () throws IOException {

        Server server = new Server();

        Kryo kryo = server.getKryo();
        kryo.register(SomeRequest.class);
        kryo.register(SomeResponse.class);

        server.start();
        server.bind(3000, 3001);

        server.addListener(new Listener() {
            public void received (Connection connection, Object object) {
               if (object instanceof SomeRequest) {
                  SomeRequest request = (SomeRequest)object;
                  System.out.println(request.text);

                  SomeResponse response = new SomeResponse();
                  response.text = "Thanks";
                  connection.sendTCP(response);
               }
            }
        });
    }

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        //SERVER_TCP_PORT = Network.SERVER_TCP_PORT;
        //SERVER_UDP_PORT = Network.SERVER_UDP_PORT;

        new GameServer();

}
}
Frotty commented 8 years ago

You need kryo as dependency as well, not only kryonet.