-
Notifications
You must be signed in to change notification settings - Fork 51
Packet
juhgiyo edited this page Jan 24, 2013
·
9 revisions
- Idea of the "Packet" is the basic unit of data to communicate between the server and the client.
#include "epse.h"
#include "Packet.h"
using namespace epl;
using namespace epse;
// SomePacketInfo.h
...
typedef enum _receivePacketType{
RECEIVE_PACKET_TYPE_DIDSOMETHING=0,
RECEIVE_PACKET_TYPE_DIDSOMETHING2,
RECEIVE_PACKET_TYPE_DIDSOMETHING3,
RECEIVE_PACKET_TYPE_ENDOFPROCESS,
}ReceivePacketType;
typedef enum _sendPacketType{
SEND_PACKET_TYPE_DOSOMETHING=0,
SEND_PACKET_TYPE_DOSOMETHING2,
SEND_PACKET_TYPE_DOSOMETHING3,
}SendPacketType;
struct SendPacket{
SendPacketType packetType;
unsigned int magicNum;
};
struct ReceivePacket{
ReceivePacketType packetType;
};
SendPacket sendPacket;
sendPacket.packetType=SEND_PACKET_TYPE_DOSOMTHING2;
sendPacket.magicNum = 1;
Packet packet(&sendPacket // pointer to the data
, sizeof(SendPacket), // byte size of the data
, true // flag whether to allocate the memory
// for the data within Packet Object or not.
);
-
- 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 pointer to the data within the Packet object according to the situation.
-
- For the details of Packet class, see EpServerEngine Documentation