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

ExCSocket.cpp

Go to the documentation of this file.
00001 // Socket.cpp: implementation of the ExCSocket class.
00002 //
00004 #include "ExCSocket.h"
00006 // Construction/Destruction
00008 
00009 ExCSocket::ExCSocket()
00010 {
00011 Guard(ExCSocket::ExCSocket())
00012         m_Port=5000;
00013         m_hSocket=socket(AF_INET,SOCK_STREAM,0);
00014         if(m_hSocket==-1)
00015         {
00016                 EXC
00017                         std::cout<<"error"<<std::endl;
00018         }
00019 UnGuard
00020 }
00021 
00022 ExCSocket::ExCSocket(int Handler){Guard(ExCSocket::ExCSocket(int handler))
00023         SetHandler(Handler);
00024 UnGuard
00025 }
00026 
00027 ExCSocket::ExCSocket(int * Handler){Guard(ExCSocket::ExCSocket(int handler))
00028         SetHandler(*Handler);
00029 UnGuard
00030 }
00031 
00032 ExCSocket::ExCSocket(ExCSocket& socket){Guard(ExCSocket::ExCSocket(ExCSocket& socket))
00033         m_Port=socket.GetHandler();
00034         m_hSocket=socket.GetHandler();
00035         m_pIP=socket.GetIp();
00036 UnGuard
00037 }
00038 
00039 
00040 
00041 ExCSocket::ExCSocket(int domaine,int protocole){Guard(ExCSocket::ExCSocket(int domaine,int protocole))
00042         m_hSocket=socket(domaine,protocole,0);
00043         if(m_hSocket==-1)
00044         {
00045                 EXC
00046         }
00047 UnGuard
00048 }
00049 
00050 ExCSocket::~ExCSocket()
00051 {
00052 Guard(ExCSocket::~ExCSocket())
00053         Close();
00054 UnGuard
00055 }
00056 
00058 // Function
00060 
00061 void ExCSocket::Init(void){Guard(ExCSocket::Init(void))
00062 
00063         if((m_pInfosHost=gethostbyname("lore"))==0)
00064         {
00065                 EXC
00066         }
00067         memcpy(&m_AdresseIP,m_pInfosHost->h_addr,m_pInfosHost->h_length);
00068                 m_pIP= new char[15];
00069         sprintf(m_pIP,"%s",inet_ntoa(m_AdresseIP));
00070 
00071         memset(&m_AdresseSocket,0,sizeof(struct sockaddr_in));
00072         m_AdresseSocket.sin_family= AF_INET;//le domaine
00073         m_AdresseSocket.sin_port=htons(m_Port);
00074         memcpy(&m_AdresseSocket.sin_addr,m_pInfosHost->h_addr,m_pInfosHost->h_length);
00075         
00076 UnGuard
00077 }
00078 
00079 char * ExCSocket::GetIp(void){Guard(ExCSocket::GetIp(void))
00080         return m_pIP;
00081 UnGuard
00082 }
00083 
00084 int ExCSocket::GetSocketPort(void){Guard(ExCSocket::GetSocketPort())
00085         return m_Port;
00086 UnGuard
00087 }
00088 
00089 void ExCSocket::SetSocketPort(int port){Guard(ExCSocket::SetSocketPort(int port))
00090         m_Port=port;
00091 UnGuard
00092 }
00093 
00094 int ExCSocket::GetHandler(){Guard(ExCSocket::GetHandler())
00095         return m_hSocket;
00096 UnGuard
00097 }
00098 
00099 void ExCSocket::SetHandler(int handler){Guard(ExCSocket::SetHandler())
00100         m_hSocket=handler;
00101 UnGuard
00102 }
00103 
00104 void ExCSocket::Close(void){Guard(void ExCSocket::Close(void))
00105         #ifndef UNIX_SRC
00106                 closesocket(m_hSocket);
00107         #endif
00108         #ifdef UNIX_SRC
00109                 close(m_hSocket);
00110         #endif
00111 UnGuard
00112 }

Generated on Tue Dec 10 18:20:05 2002 for ExNihilo by doxygen1.3-rc1