-
Notifications
You must be signed in to change notification settings - Fork 7
Creation of packets
A packet basically is an object that is supposed to be transmitted via a connection between two opponents (in this case the connection is called Session). You should be familiar with this basic idea.
Firstly, we create a class with a name that should contain the word 'packet', or at least be descriptive. This class is going to extend the Packet class of Hydra. The second important thing is to use the Packet id annotation, it takes a byte that indicates the id of the packet. The id is really important for the protocol in order to be able to distinguish the packets. The third important thing is an empty constructor. Every Packet class must define an empty constructor (constructor without any parameters). This constructor is called when deserializing the packet at the opponent it was sent to. In case you would like to invoke something in exactly that moment, the constructor can be filled with instructions and is going to be called, but still no parameters are allowed for that constructor.
After the set up of the basic class we proceed to define the methods used to receive and send data, which is supposed to be transmitted, via the packet. Here is a simple example that is illustrates the following things: example Packet Extending the Packet class forces the child class to override the methods 'read' and 'write'. These methods are used by the protocol to read and write data from the Netty channels (the sessions/connection between the communicating opponents). There are several special methods, that can be invoked for different data types. Take a look at the Packet class and read the documentation of the methods in order to get familiar with the possibilities.
- Home
- Example usage of Hydra: Building a simple chat application
- Advanced example usage of Hydra: Building a small key-value store
- Example usage of Hydra's custom class serialization