Kryonet - how to recognize a packet type?

Hello.

How does Kryonet recognize different packets? By types, names, bytes?

A friend told me to make a base class named Packet with a String in it, extend it in every single packet class and put a ‘name’ of each packet, but it doesn’t work - Kryonet is faster and shows in the console, that the wrong packet has been read.

I just don’t know how to discover similar packet types (with only different names).

Here is an example:

  static public class PlayerPosition extends Packet{
        public float x, y;
    }

    static public class StartingLeft extends Packet{
        public boolean startingLeft;
    }

    static public class ReadyForCasualGame extends Packet{

    }

    static public class IamReady extends Packet{

    }

When I send ‘ReadyForCasualGame’ from the client, the server always reads this as ‘IamReady’ packet.

The only reason I could think that the server would be reading a packet incorrectly would be because you didn’t register your classes on both ends in the same order. Kryonet uses indices to indicate which class is what and how to deserialize it, so registering packets in the wrong order would result in the wrong index being serialized from client to server…

GOD, Thank you. I didn’t register one class.

I would highly recommend just having a common method that accepts the Kryo instance as a parameter, and in that method registering all your classes. Then from your server, call that method, client as well.