Skip to content

Commit

Permalink
Mise en place des fonctions f*
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard CATTEZ committed Feb 2, 2015
1 parent 5232ba4 commit 6a86b3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
Binary file modified webserver/l7pserv
Binary file not shown.
17 changes: 7 additions & 10 deletions webserver/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ int main(int argc, char **argv)
int port;
int socket_serveur;
int socket_client;
int read_message;
char buf[256];
FILE * stream;

if (argc < 2) {
printf("Usage: /l7pserv [port]\n");
Expand Down Expand Up @@ -36,25 +36,22 @@ int main(int argc, char **argv)
traitement_signal(socket_client);
socket_client = ecouter_connexion(socket_serveur);
if (socket_client != 0)
{
{
stream = fdopen(socket_client, "w+");
while(1)
{
/* On lit le buffer */
read_message = read(socket_client, buf, sizeof(buf));
if (read_message <= 0)
if (fgets(buf, sizeof(buf), stream) == NULL)
{
if (read_message == -1)
{
perror("read");
}
printf("Client(id=%d) disconnect\n", getpid());
fclose(stream);
exit(0);
}

/* On écrit le message de l'utilisateur à l'utilisateur (echo) */
if (write(socket_client, buf, read_message) != -1)
if (fprintf(stream, "<L7Pserv> %s", buf) != -1)
{
/* On notifie au serveur le message du client */
buf[read_message] = '\0';
printf("Client(id=%d) send: %s", getpid(), buf);
}
}
Expand Down

0 comments on commit 6a86b3a

Please sign in to comment.