1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
//Surcharge du constructeur
void Client :: initSock(int csock){
sock=csock;
std::cout<<"Client :: ajout 1 client : "<<sock<<std::endl;
//Lancement du Thread
pthread_t unThread;
if((idThread = pthread_create(&unThread,NULL,threadClient,this))== -1){
perror("Error :: create thread failure ");
exit(0);
}
}void Client :: run(){
rep=false;
while(1){
if(rep){
if((send(sock,msgTampon.c_str(),strlen(msgTampon.c_str())+1,0))== -1){
perror("Error : send ");
}
rep=false;
}
}
}
//Envoyer messge au client
void Client :: sendMsg(std::string msg){
msgTampon=msg;
std::cout<<"met dans tampon "<<msgTampon<<std::endl;
rep=true;
}
//Creation de thread pour chaque client
void * threadClient(void * zz){
Client * p=(Client *)zz;
p->run();
} |
Partager