#include <stdio.h>      /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), bind(), and connect() */
#include <arpa/inet.h>  /* for sockaddr_in and inet_ntoa() */
#include <stdlib.h>     /* for atoi() and exit() */
#include <string.h>     /* for memset() */
#include <unistd.h>     /* for close() */

#define MAXPENDING 5    /* Maximum outstanding connection requests */
#define RCVBUFSIZE 32

int main()
{
    int servSock;                    /* Socket descriptor for server */
    int clntSock;                    /* Socket descriptor for client */
    struct sockaddr_in echoServAddr; /* Local address */
    struct sockaddr_in echoClntAddr; /* Client address */
    unsigned short echoServPort;     /* Server port */
    unsigned int clntLen;            /* Length of client address data structure */
    char echoBuffer[RCVBUFSIZE];        /* Buffer for echo string */
    int recvMsgSize;                    /* Size of received message */


    echoServPort = 2000;  /* First arg:  local port */

    /* Create socket for incoming connections */
	  /* TODO: mettre le code... */
      
    /* Construct local address structure */
    memset(&echoServAddr, 0, sizeof(echoServAddr));   /* Zero out structure */
    echoServAddr.sin_family = AF_INET;                /* Internet address family */
    echoServAddr.sin_addr.s_addr = htonl(INADDR_ANY); /* Any incoming interface */
    echoServAddr.sin_port = htons(echoServPort);      /* Local port */

    /* Bind to the local address */
      
	  /* TODO: mettre le code... */

    /* Mark the socket so it will listen for incoming connections */
       
	   /* TODO: mettre le code... */

    for (;;) /* Run forever */
    {
        /* Set the size of the in-out parameter */
        clntLen = sizeof(echoClntAddr);

        /* Wait for a client to connect */
           
		   /* TODO: mettre le code... */

        /* clntSock is connected to a client! */

        printf("Handling client %s\n", inet_ntoa(echoClntAddr.sin_addr));


    	/* Receive message from client */
    	   /* TODO: mettre le code... */
		   
		   
    	/* Send received string and receive again until end of transmission */
    	while (recvMsgSize > 0)      /* zero indicates end of transmission */
    	{
        	/* Echo message back to client */
				/* TODO: mettre le code... */

			/* See if there is more data to receive */
			   
			   /* TODO: mettre le code... */
    	}

    	close(clntSock);    /* Close client socket */

    }
    /* NOT REACHED */
}

