#include "cserver.h"
// don't forget to add cbase.cpp, cconnection.cpp and cserver.cpp to your project

int main()
{
   cbase* server=new cserver(12345);
   // create server listening on port 12345

   while (1)
   {
      char buffer[256]="Packet from server";
      // single packet can be up to 255 bytes long

      server->write_packet(1,buffer);
      // first parameter is the target id (2-64) or 1 to send the packet to all clients

      server->update();
      // sending and receiving is actually done here

      int i;
      // to store source id
      do
      {
         i=server->read_packet(buffer);
         // read_packet() returns source id or 0 if no packet is available
         if (i>0)
         // if a packet has been received
            if (strlen(buffer)==0) printf("ID %i connected/disconnected.\n",i);
            // if buffersize is 0 the client with id i has just connected/disconnected
            else printf("ID %i sent '%s'.\n",i,buffer);
            // if buffersize is >0 a packet has been received
      }
      while (i>0);
      // as long as packets are available
   }

   delete server;
   // shutdown and delete server

   return 0;
}
