Skip to content
juhgiyo edited this page Oct 26, 2014 · 3 revisions

This is a packet class which is responsible for the following:

  • Basic unit of data to communicate between the server and the client for EpServerEngine.cs.

How to use this packet class?

  • PacketSerializer
  • MemoryStream
  • etc.

For example, if you define the packet structure as above, you can create Packet object as below to send it to the server/client.


Serializable Class Example:

// PacketSerializer
PacketSerializer<SomeData> serializer = new PacketSerializer<SomeData>(new SomeData(14));
byte[] packet = serializer.GetPacketRaw();
Packet sendPacket= new Packet(packet             // byte array of packet
                              , packet.Count()   // byte size of the data
                              , false);          // flag whether to allocate the memory
                                                 //   for the data within Packet Object or not.

MemoryStream Example:

// MemoryStream
byte[] packet = new byte[12];
MemoryStream stream = new MemoryStream(packet);
stream.Write(BitConverter.GetBytes((int)PacketCode.SOME_CODE), 0, 4);
stream.Write(BitConverter.GetBytes((long)14),0,8);
Packet sendPacket = new Packet(packet, packet.Count(), false);
    • Note that since copying memory for packet is critical on the performance in Server development, you can choose whether to allocate the memory for the Packet object, or just hold the reference to the data byte array within the Packet object according to the situation.