From e7eb70a1342df26588b8800db7340e186d7fd5f7 Mon Sep 17 00:00:00 2001 From: Yohan Boujon Date: Wed, 18 Jan 2023 09:32:22 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20de=20fonction=20modeBoiteAuxLettres()?= =?UTF-8?q?=20qui=20permet=20de=20lancer=20un=20mode=20TCP=20qui=20attend?= =?UTF-8?q?=20=C3=A0=20l'infini.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- header/puit.h | 1 + src/puit.c | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/header/puit.h b/header/puit.h index 7cfd3ed..f6e1032 100644 --- a/header/puit.h +++ b/header/puit.h @@ -6,5 +6,6 @@ int launchPuit(int nombreMessage,int tailleMessage,int isTCP,int port,char * ipAddress,int isBAL); int initSocket(int socketType, struct sockaddr_in * socketStruct, int port, char * ipAddress); int receiveMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct, int isTCP); +int modeBoiteAuxLettres(struct sockaddr_in socketStruct, int socketType, int port, char * ipAddress); #endif \ No newline at end of file diff --git a/src/puit.c b/src/puit.c index 8614c98..934498d 100644 --- a/src/puit.c +++ b/src/puit.c @@ -5,12 +5,13 @@ int launchPuit(int nombreMessage,int tailleMessage,int isTCP,int port,char * ipA int sock,socketType; struct sockaddr_in socketPuit; socketType = (isTCP) ? SOCK_STREAM : SOCK_DGRAM; - sock = initSocket(socketType,&socketPuit,port,ipAddress); if(isBAL) { printf("Mode Boîte aux Lettres\n"); + modeBoiteAuxLettres(socketPuit,socketType,port,ipAddress); return 0; } + sock = initSocket(socketType,&socketPuit,port,ipAddress); receiveMultipleData(nombreMessage,tailleMessage,sock,socketPuit,isTCP); close(sock); return 0; @@ -33,6 +34,31 @@ int initSocket(int socketType, struct sockaddr_in * socketStruct, int port, char return sockReturn; } +int modeBoiteAuxLettres(struct sockaddr_in socketStruct, int socketType, int port, char * ipAddress) +{ + char messageRecu[30+1]; + int n, i=1, longueurRecu = sizeof(socketStruct),sock,oldSock; + while(1) + { + n=1; + oldSock = initSocket(socketType,&socketStruct,port,ipAddress); + listen(oldSock,5); + sock = accept(oldSock,(struct sockaddr *)&socketStruct,(socklen_t * restrict)&longueurRecu); + while(n>0) + { + n = read(sock,messageRecu,30); + messageRecu[n] = '\0'; + if(n>0) + { + printf("Puit\tReception n°%d (%d) :\t[%s]\n",i,n,messageRecu); + i++; + } + } + close(sock); + close(oldSock); + } +} + int receiveMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct, int isTCP) { char messageRecu[tailleMessage+1];