MinecraftForge/FML — pull request #235 by smith61 (2013-05-31 03:00:41+00:00)
Title: Adds Packet system for use over Minecraft Channels

This adds a Packet system that can be used over Minecraft channels

There are two main packet classes that mods can extend

The first is a basic packet ModPacket. ModPacket has two methods that packets must override, readPacketData and writePacketData. They do exactly what the name suggests.

The second packet is RecyclablePacket. This is a special packet that gets recycled after it is read in and handled. This is to reduce the object churn on busy channels caused from the creation of many small packets in a short amount of time. It provides an extra method called recycle that is used to clean up any resources a packet may have and to reset the packet for reading again. Most packets should extend this class instead of ModPacket unless there is a good reason.

The next part of the system is the PacketHandler. The class that implements this interface is called when a packet has been received and successfully read in. It provides only one method to implement.

Now to the meat of the system. ChannelConnection and PacketRepository. These classes work together to read, write, register, and handle all packets sent over a Minecraft channel.

PacketRepository is a repository of packets. It handles all registration and creation of packets for reading. PacketRepositories can be shared across multiple ChannelConnections or any other Packet system.

ChannelConnection is the interaction point for sending Packets over a channel. It handles all the reading, writing, and handling of packets sent over a channel. On creation it binds to a Minecraft channel and to a PacketRepository and optionally a PacketHandler.

[Example](https://dl.dropboxusercontent.com/u/19977649/forge/ChannelConnectionExample.zip)

If this post or the examples still leaves questions about how this works you can look through the javadoc comments or post a question here.