diff --git a/Sioux/sioux b/Sioux/sioux index f94e82d..349f38b 100755 Binary files a/Sioux/sioux and b/Sioux/sioux differ diff --git a/Sioux/sioux.c b/Sioux/sioux.c index 2573448..7adeaad 100644 --- a/Sioux/sioux.c +++ b/Sioux/sioux.c @@ -3,11 +3,12 @@ #include #include #include +#include #include #include #include - +#define BUFF_SIZE 100 int initialisationServeur(char* service) { @@ -56,41 +57,75 @@ int initialisationServeur(char* service) return sock_fd; } -void maFonction(int sock) +void reponseConnexion(int sock) { printf("Connected\n"); - char buffer[100]; + char buffer[BUFF_SIZE]; FILE* sockdial_stream = fdopen(sock, "a+"); - fgets(buffer, 100, sockdial_stream); + while(strcmp(buffer, "EXIT\n")!=0) + { + fgets(buffer, BUFF_SIZE, sockdial_stream); - printf("%s\n", buffer); + printf("Le message reçu : %s", buffer); + + fprintf(sockdial_stream, "Ceci est une réponse du serveur TCP.\n"); + + } + printf("Fin de la connexion\n"); fclose(sockdial_stream); + } int boucleServeur(int socket, void(* fctConnex)(int)) { int sock_dial; - - + printf("------- Début boucle serveur TCP -------\n\n"); + while(1) { - printf("MAH !\n"); + printf("-- boucle --\n"); if((sock_dial=accept(socket, NULL, NULL)) < 0){ fprintf(stderr, "Error accept dialogue\n"); return -1; } - printf("ACCEPTED\n"); + printf("Dialogue ACCEPTED\n"); fctConnex(sock_dial); } } +void argPortParsing(int argc, char* argv[], char* port) +{ + struct option port_arg={"port", 1, NULL, 'p'}; + char opt; + int longindex; + + while( (opt=getopt_long(argc, argv, "p:", &port_arg, &longindex)) !='p' && opt!=-1) {} -int main(void) + if(opt=='p') + { + strcpy(port, optarg); + printf("%s\n", optarg); + } + else + { + printf("La syntaxe doit être ./sioux -p ou ./sioux --port "); + } +} + +int main(int argc, char* argv[]) { - int sock_fd=initialisationServeur("2020"); - boucleServeur(sock_fd, maFonction); + char port[10]="80"; + argPortParsing(argc, argv, port); + + + int sock_fd=initialisationServeur(port); + + if( sock_fd==-1 ) { fprintf(stderr, "Initialisaiton du serveur impossible\n"); return -1; } + + + boucleServeur(sock_fd, reponseConnexion); return 0; } -- libgit2 0.21.2