-
Notifications
You must be signed in to change notification settings - Fork 27
Packet
juhgiyo edited this page Oct 26, 2014
·
3 revisions
- Basic unit of data to communicate between the server and the client for EpServerEngine.cs.
- 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.
// 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
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 thePacket
object according to the situation.
- 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