Main Page Namespace List Class Hierarchy Alphabetical List Data Structures File List Namespace Members Data Fields Globals

# ExCSocketServer.cpp

Go to the documentation of this file.

    00001 // ExCSocketServeur.cpp: implementation of the ExCSocketServer class.
    00002 //
    00004 #include "ExCSocketServer.h"
    00006 // Construction/Destruction
    00008
    00009 ExCSocketServer::ExCSocketServer(){Guard(ExCSocketServer::ExCSocketServer())
    00010         ExCSocket();
    00011 UnGuard
    00012 }
    00013
    00014 ExCSocketServer::ExCSocketServer(int domaine,int protocole){Guard(ExCSocketServer::ExCSocketServer())
    00015         ExCSocket(domaine,protocole);
    00016 UnGuard
    00017 }
    00018
    00019 ExCSocketServer::~ExCSocketServer(){Guard(ExCSocketServer::~ExCSocketServer())
    00020         close(m_hSocket);
    00021 UnGuard
    00022 }
    00023
    00024 int ExCSocketServer::Listen(){Guard(ExCSocketServer::Listen())
    00025         int hNewSocket;
    00026
    00027         unsigned int tailleSockaddr_in;
    00028
    00029         tailleSockaddr_in= sizeof(struct sockaddr_in);
    00030         hNewSocket=accept(m_hSocket,(struct sockaddr *)&m_AdresseSocket,&tailleSockaddr_in);
    00031         if(hNewSocket==-1)
    00032         {
    00033                 close(m_hSocket);
    00034                 Trace(Erreur sur le listen)
    00035                 EXC
    00036         }
    00037         return hNewSocket;
    00038 UnGuard
    00039 }
    00040
    00041 void ExCSocketServer::Init(void){Guard(CSocket::Init(void))
    00042
    00043         if((m_pInfosHost=gethostbyname("lore"))==0)
    00044         {
    00045                 Trace("Erreur d'aquisition sur le host");
    00046                 EXC
    00047         }
    00048         memcpy(&m_AdresseIP,m_pInfosHost->h_addr,m_pInfosHost->h_length);
    00049                 m_pIP= new char[15];
    00050         sprintf(m_pIP,"%s",inet_ntoa(m_AdresseIP));
    00051
    00052         memset(&m_AdresseSocket,0,sizeof(struct sockaddr_in));
    00053         m_AdresseSocket.sin_family= AF_INET;//le domaine
    00054         m_AdresseSocket.sin_port=htons(m_Port);
    00055         memcpy(&m_AdresseSocket.sin_addr,m_pInfosHost->h_addr,m_pInfosHost->h_length);
    00056
    00057         if(bind(m_hSocket,(struct sockaddr *)&m_AdresseSocket,sizeof(struct sockaddr_in))==-1)
    00058         {
    00059                 Trace(Erreur sur le bind su socket)
    00060                 EXC
    00061         }
    00062         if(listen(m_hSocket,SOMAXCONN)==-1)
    00063         {
    00064                 close(m_hSocket);
    00065                 EXC
    00066         }
    00067 UnGuard
    00068 }