Ajouter 'tcp puit'
This commit is contained in:
parent
f0b339953d
commit
9fc81cedc0
1 changed files with 48 additions and 0 deletions
48
tcp puit
Normal file
48
tcp puit
Normal file
|
@ -0,0 +1,48 @@
|
|||
//---------PUITS---------//
|
||||
else{
|
||||
|
||||
printf("on est dans le puits\n");
|
||||
printf("nb de tampons à recevoir = infini\n");
|
||||
|
||||
//création du socket
|
||||
if((sock=socket(AF_INET, SOCK_STREAM,0)) == -1) {
|
||||
printf("echec de la creation du socket\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//construction de l'@ du socket
|
||||
memset((char*)&adr_local, 0, sizeof(adr_local));
|
||||
adr_local.sin_family=AF_INET;
|
||||
adr_local.sin_port=port;
|
||||
adr_local.sin_addr.s_addr=INADDR_ANY;
|
||||
|
||||
//bind
|
||||
if (bind(sock,(struct sockaddr*)&adr_local, lg_adr_local) == -1) {
|
||||
printf("echec du bind\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//dimensionnement de la file de demandes de connexion
|
||||
if (listen(sock, nb_max_connexion) == -1) {
|
||||
printf("echec du listen\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//acceptation d'une demande de connexion
|
||||
if((sock_bis=accept(sock,(struct sockaddr *)&adr_em, &lg_adr_em)) == -1) {
|
||||
printf("echec du accept\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//reception
|
||||
while ((lg_mesg=recv(sock_bis, pmesg, lg_max, 0))>0){
|
||||
afficher_message(pmesg, lg_mesg);
|
||||
//sleep(1);
|
||||
}
|
||||
|
||||
//fermeture
|
||||
if (close(sock)==-1) {
|
||||
printf("echec de destruction du socket\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue