#include #include #include #include #include #include #include #include #include void construire_message(char *message, char motif, int lg) { int i; for (i=0; i<(lg); i++) { message[i] = motif; } } void afficher_message(char *message, int lg, int num) { int i; printf("n°%d (%d) [----%d", num, lg, num); for (i=0; ih_addr, hp->h_length); if (lg_mesg<6){ printf("Erreur: la taille du buffer doit être >=6.\n"); exit(1); } //envoi for(i=0; ih_addr, hp->h_length); printf("SOURCE: socket\n"); //connexion if (connect(sock,(struct sockaddr*)&adr_distant, lg_adr_dest) == -1) { printf("echec de la connexion\n"); exit(1); } printf("SOURCE: connect\n"); if (recepteur == 1) { lg_max=lg_mesg; if (nb_message == -1) { int count = 0; while ((lg_mesg=recv(sock, pmesg, lg_max, 0))>0) { count++; printf("PUITS: Reception "); afficher_message(pmesg, lg_mesg, count); } } else { for (int k=0; k0) { printf("PUITS: Reception "); afficher_message(pmesg, lg_mesg, (k+1)); } } } } else { //envoi for(i=0; i0) { count++; printf("PUITS: Reception "); afficher_message(pmesg, lg_mesg, count); } /* } else { */ /* for (int k=0; k0) { */ /* printf("PUITS: Reception "); */ /* afficher_message(pmesg, lg_mesg, (k+1)); */ /* } */ /* } */ /* } */ } } if (close(sock)==-1) { printf("Échec de destruction du socket\n"); exit(1); } printf("PUITS: fin\n"); } } free(pmesg); }