mirror of
https://github.com/yoboujon/tsock.git
synced 2025-06-08 14:00:50 +02:00
ajout de fonction modeBoiteAuxLettres() qui permet de lancer un mode TCP qui attend à l'infini.
This commit is contained in:
parent
a93ceba375
commit
e7eb70a134
2 changed files with 28 additions and 1 deletions
|
@ -6,5 +6,6 @@
|
||||||
int launchPuit(int nombreMessage,int tailleMessage,int isTCP,int port,char * ipAddress,int isBAL);
|
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 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 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
|
#endif
|
28
src/puit.c
28
src/puit.c
|
@ -5,12 +5,13 @@ int launchPuit(int nombreMessage,int tailleMessage,int isTCP,int port,char * ipA
|
||||||
int sock,socketType;
|
int sock,socketType;
|
||||||
struct sockaddr_in socketPuit;
|
struct sockaddr_in socketPuit;
|
||||||
socketType = (isTCP) ? SOCK_STREAM : SOCK_DGRAM;
|
socketType = (isTCP) ? SOCK_STREAM : SOCK_DGRAM;
|
||||||
sock = initSocket(socketType,&socketPuit,port,ipAddress);
|
|
||||||
if(isBAL)
|
if(isBAL)
|
||||||
{
|
{
|
||||||
printf("Mode Boîte aux Lettres\n");
|
printf("Mode Boîte aux Lettres\n");
|
||||||
|
modeBoiteAuxLettres(socketPuit,socketType,port,ipAddress);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
sock = initSocket(socketType,&socketPuit,port,ipAddress);
|
||||||
receiveMultipleData(nombreMessage,tailleMessage,sock,socketPuit,isTCP);
|
receiveMultipleData(nombreMessage,tailleMessage,sock,socketPuit,isTCP);
|
||||||
close(sock);
|
close(sock);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -33,6 +34,31 @@ int initSocket(int socketType, struct sockaddr_in * socketStruct, int port, char
|
||||||
return sockReturn;
|
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)
|
int receiveMultipleData(int nombreMessages, int tailleMessage, int sock, struct sockaddr_in socketStruct, int isTCP)
|
||||||
{
|
{
|
||||||
char messageRecu[tailleMessage+1];
|
char messageRecu[tailleMessage+1];
|
||||||
|
|
Loading…
Add table
Reference in a new issue