Packets

Packets are classes which contain a payload which can be transmitted over the internet.

Important

The packet’s payload must be serializable with SerializeLib.

The payload can be accessed through the Payload field.

Creating packets

With an empty payload

using PacketLib.Packet;

public class ExamplePacket : Packet<EmptyPayload>
{

}

With a serializable payload

using PacketLib.Packet;

public class ExamplePacket : Packet<long>
{

}

Creating custom payloads

Any serializable object can be used as a payload, so for a payload with a bool and an int, this would be the code.

using SerializeLib.Attributes;

[SerializeClass]
public class ExamplePayload
{
    [SerializeField] public int ExampleInt;
    [SerializeField] public bool ExampleBool;
}

Adding functionality to packets

There are two functions for processing packets, one for the client, one for the server.

public override void ProcessClient<T>(NetworkClient<T> client)

Processes a packet on the client. The NetworkClient is passed as the client argument.

public override void ProcessServer<T>(NetworkServer<T> server, ClientRef<T> source)

Processes a packet on the server. The NetworkServer is passed as the server argument, and the ClientRef the packet was received from is passed as the source argument.