Commit 19fd567447c5a6f01a56d7fd6c7e63199c244d34
1 parent
b82d369c
feat: receive messages from multiple client
Showing
1 changed file
with
21 additions
and
5 deletions
Show diff stats
server.c
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | #include <netinet/tcp.h> |
10 | 10 | #include <poll.h> |
11 | 11 | #include "server.h" |
12 | - | |
12 | +#include <unistd.h> | |
13 | 13 | |
14 | 14 | #define MAX_LIGNE 512 |
15 | 15 | |
... | ... | @@ -122,9 +122,11 @@ int boucleServeur2(int ecoute) |
122 | 122 | while(1){ |
123 | 123 | |
124 | 124 | //poll |
125 | - | |
125 | + int nb = poll(descripteurs, 1024, -1); | |
126 | + | |
127 | + if(nb<0){ perror("main.poll"); exit(EXIT_FAILURE); } | |
126 | 128 | |
127 | - //if (ecoute est active){ | |
129 | + if( (descripteurs[0].revents&POLLIN) !=0){//ecoute est active | |
128 | 130 | /* Attente d'une connexion */ |
129 | 131 | int dialogue=accept(ecoute,NULL,NULL); |
130 | 132 | if(dialogue<0) return -1; |
... | ... | @@ -136,7 +138,21 @@ int boucleServeur2(int ecoute) |
136 | 138 | |
137 | 139 | /* Passage de la socket de dialogue a la fonction de traitement */ |
138 | 140 | //if(traitement(dialogue)<0){ shutdown(ecoute,SHUT_RDWR); return 0;} |
139 | - //} | |
141 | + } | |
142 | + | |
143 | + for(int i = 0; i < LongueurPoll-1; i++){ | |
144 | + if( (descripteurs[i+1].revents&POLLIN) !=0){ //A lire | |
145 | + //printf("Gestion Client %i \n", i+1); | |
146 | + FILE* f = fdopen(descripteurs[i+1].fd, "a+"); | |
147 | + | |
148 | + char ligne[MAX_LIGNE]; | |
149 | + fgets(ligne,MAX_LIGNE,f); | |
150 | + printf(">%i$ %s\n", i+1, ligne); | |
151 | +sleep(1); | |
152 | + | |
153 | + } | |
154 | + } | |
155 | + | |
140 | 156 | } |
141 | - | |
157 | + | |
142 | 158 | } | ... | ... |