#include <SocketTCP.h>
Inheritance diagram for SocketTCP:
Public Member Functions | |
SocketTCP () | |
SocketTCP (int socket) | |
Constructeur par recopie, utilisé seulement par la méthode Accept afin de construire une nouvelle socket à partir du résultat de la primitive TCP accept(). | |
SocketTCP (unsigned int port) throw (SocketException) | |
Construction typique d'une scoket utilisée par un serveur. | |
SocketTCP (string ad, unsigned int port) throw (SocketException) | |
Construction typique d'une scoket utilisée par un client. | |
SocketTCP (Socket *s) | |
Constructeur par copie d'un pointeur sur l'objet de base Socket. | |
SocketTCP (const SocketTCP &s) | |
Constructeur par recopie. | |
void | operator= (const SocketTCP &s) |
Surcharge de = (Contructeur par recopie). | |
~SocketTCP () | |
Socket * | Accept () throw (SocketException) |
Méthode bloquante attendant la connexion d'un client TCP Usage typique: Socket *s=new SocketTCP((unsigned int)port); Socket *ecoute=s->Accept(); //PENSER au delete car un new SocketTCP est fait dans cette méthode. | |
void | Envoyer (string msg) const throw (SocketException) |
Envoie du message msg via la socket. | |
string | Ecouter () throw (SocketException) |
Attent un message de l'extrémité de la socket et le renvoie. |
Definition at line 36 of file SocketTCP.h.
SocketTCP::SocketTCP | ( | ) | [inline] |
SocketTCP::SocketTCP | ( | int | socket | ) |
Constructeur par recopie, utilisé seulement par la méthode Accept afin de construire une nouvelle socket à partir du résultat de la primitive TCP accept().
socket |
Definition at line 23 of file SocketTCP.cpp.
References Socket::mSocket.
00023 { 00024 mSocket=socket; 00025 }
SocketTCP::SocketTCP | ( | unsigned int | port | ) | throw (SocketException) |
Construction typique d'une scoket utilisée par un serveur.
Ecoute toutes les interfaces locales
port | Port d'écoute |
Definition at line 27 of file SocketTCP.cpp.
00027 : Socket(port){ 00028 int retour; 00029 struct sockaddr_in adresse; 00030 mSocket=socket(AF_INET,SOCK_STREAM,0); 00031 if (mSocket<0) throw(SocketException(1)); 00032 adresse.sin_family=AF_INET; 00033 adresse.sin_port = htons((u_short)port); 00034 adresse.sin_addr.s_addr=INADDR_ANY; 00035 retour = bind(mSocket,(struct sockaddr *)&adresse,sizeof(adresse)); 00036 if (retour<0) throw(SocketException(2)); 00037 listen(mSocket,7); 00038 }
SocketTCP::SocketTCP | ( | string | ad, | |
unsigned int | port | |||
) | throw (SocketException) |
Construction typique d'une scoket utilisée par un client.
Se connecte sur ad:port
ad | Adresse distante | |
port | Port distant |
Definition at line 40 of file SocketTCP.cpp.
00040 : Socket(ad,port){ 00041 struct sockaddr_in adresse; 00042 struct hostent *recup; 00043 mSocket=socket(AF_INET, SOCK_STREAM, 0); 00044 if (mSocket < 0) throw(SocketException(1)); 00045 recup = gethostbyname(ad.c_str()); 00046 if (recup == NULL) throw(SocketException(3)); 00047 memcpy((char *)&adresse.sin_addr, (char *)recup->h_addr, recup->h_length); 00048 adresse.sin_family = AF_INET; 00049 adresse.sin_port = htons((u_short) port); 00050 if (connect(mSocket, (struct sockaddr *)&adresse, sizeof(adresse)) == -1) throw(SocketException(4)); 00051 }
SocketTCP::SocketTCP | ( | Socket * | s | ) |
Constructeur par copie d'un pointeur sur l'objet de base Socket.
s | Socket* |
Definition at line 63 of file SocketTCP.cpp.
00063 : Socket(s){ 00064 }
SocketTCP::SocketTCP | ( | const SocketTCP & | s | ) |
Constructeur par recopie.
s | Objet de base |
Definition at line 67 of file SocketTCP.cpp.
References Socket::mCryptage, and Socket::mSocket.
SocketTCP::~SocketTCP | ( | ) |
Definition at line 77 of file SocketTCP.cpp.
References Socket::mSocket.
00077 { 00078 close(mSocket); 00079 }
void SocketTCP::operator= | ( | const SocketTCP & | s | ) |
Surcharge de = (Contructeur par recopie).
s | Objet de base |
Definition at line 72 of file SocketTCP.cpp.
References Socket::mCryptage, and Socket::mSocket.
Socket * SocketTCP::Accept | ( | ) | throw (SocketException) [virtual] |
Méthode bloquante attendant la connexion d'un client TCP Usage typique: Socket *s=new SocketTCP((unsigned int)port); Socket *ecoute=s->Accept(); //PENSER au delete car un new SocketTCP est fait dans cette méthode.
..
Implements Socket.
Definition at line 53 of file SocketTCP.cpp.
References Socket::mSocket, and SocketTCP().
00053 { 00054 int socket; 00055 struct sockaddr_in socketEntrante; 00056 socklen_t taille=sizeof(socketEntrante); 00057 socket=accept(mSocket,(struct sockaddr*) &socketEntrante,&taille); 00058 if(socket==-1) throw(SocketException(5)); 00059 Socket *s=new SocketTCP(socket); 00060 return s; 00061 }
Here is the call graph for this function:
void SocketTCP::Envoyer | ( | string | msg | ) | const throw (SocketException) [virtual] |
Envoie du message msg via la socket.
msg | Le message à envoyer |
Implements Socket.
Definition at line 81 of file SocketTCP.cpp.
00081 { 00082 int s=send(mSocket,(mCryptage->Crypter(msg)).c_str(),msg.length(),0); 00083 if(s==-1){ 00084 throw(SocketException(6)); 00085 } 00086 }
string SocketTCP::Ecouter | ( | ) | throw (SocketException) [virtual] |
Attent un message de l'extrémité de la socket et le renvoie.
Implements Socket.
Definition at line 88 of file SocketTCP.cpp.
References Cryptage::Decrypter(), Socket::mCryptage, and Socket::mSocket.
00088 { 00089 char buffer[BUFSIZ]; 00090 int s=recv(mSocket,buffer,BUFSIZ,0); 00091 if (s==-1) throw(SocketException(7)); 00092 else if(s==0) throw(SocketException(9)); 00093 else { 00094 buffer[s]=0; 00095 return mCryptage->Decrypter(buffer); 00096 } 00097 }
Here is the call graph for this function: