ServeurPrincipal.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Pierre Schmitt, Ludovic Giacomello, Nhi Ly   *
00003  *      *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef SERVEURPRINCIPAL_H
00022 #define SERVEURPRINCIPAL_H
00023 
00024 #include<string>
00025 #include<iostream>
00026 
00027 #include "SocketTCP.h"
00028 #include "TraitementClient.h"
00029 #include "TableauDyn.h"
00030 
00034 class ServeurPrincipal{
00035 public:
00041         ServeurPrincipal(unsigned int port){ 
00042                 cout<<"SP ServeurPrincipal::Création du serveur principal"<<endl;
00043                 try{
00044                         mSocketEcoute=new SocketTCP((unsigned int)port); 
00045                 } catch(SocketException e){ 
00046                         e.Afficher(); 
00047                         exit(-1); 
00048                 }
00049                 AttendreClient();
00050         }
00051 
00052         ~ServeurPrincipal(){ 
00053                 cout<<"~ServeurPrincipal()"<<endl;
00054                 delete mSocketEcoute; 
00055                 BdD::KillInstance();
00056                 Partie::KillInstance();
00057         }
00058 
00062         void AttendreClient(){
00063                 cout<<"SP ServeurPrincipal::Attente des clients"<<endl;
00064                 Socket *s;
00065                 unsigned int nb=0;
00066                 while(1){
00067                         s=mSocketEcoute->Accept();
00068                         cout<<endl<<"SP ServeurPrincipal::Connexion d'un client"<<endl;
00069                         //Passer la nouvelle socket à un thread qui va gérer le traitement
00070                         mTC.ConsQueue(new TraitementClient(s));
00071                         mTC[nb]->Demarrer();
00072                         nb++;
00073                 }
00074                 delete s;
00075         }
00076 private:
00080         Socket *mSocketEcoute;
00081 
00085         TableauDyn<TraitementClient *> mTC;
00086 
00087 };
00088 
00089 #endif

Generated on Wed Jan 2 14:01:41 2008 for Pacman by  doxygen 1.5.1