BaseServerWorker

juhgiyo edited this page Nov 14, 2012 · 4 revisions

BaseServerWorker Usage

  • Idea of the "BaseServerWorker" is communicating the packets with the client whatever the way you prefer.

Linking

// SomeServerWorker.h
#include "epse.h"
using namespace epl;
using namespace epse;

Server Worker Declaration Example

// SomeServerWorker.h
class SomeServerWorker:public BaseServerWorker
{
public:
   SomeServerWorker();
   SomeServerWorker(const SomeServerWorker& b);
   virtual ~SomeServerWorker();
   SomeServerWorker & operator=(const SomeServerWorker&b)
   {
      if(this!=&b)
      {
         BaseServerWorker::operator =(b);
      }
      return *this;
   }
protected:
   virtual BasePacketParser* createNewPacketParser();;
};

Server Worker Implementation Example

// SomeServerWorker.cpp
#include "SomeServerWorker.h"

SomeServerWorker::SomeServerWorker():BaseServerWorker()
{
}

SomeServerWorker::SomeServerWorker(const SomeServerWorker& b):BaseServerWorker(b)
{
}

SomeServerWorker::~SomeServerWorker()
{
}

BasePacketParser* SomeServerWorker::createNewPacketParser()
{
   return EP_NEW SomePacketParser();
}
  • * Note that SomePacketParser object will be created/destroyed automatically by BaseServerWorker. For the details of SomePacketParser class, see BasePacketParser

Server Worker Receive Packet Details

  • When Server Worker receives a packet, the Server Worker will create new PacketParser object for each packet, it receives.
  • PacketParser will be run as a new thread, and the parsing will take place in the newly created thread.
  • For more detail, please see BasePacketParser