1 void ClientEcho(FILE * filein, int socket)
3 char sendbuff[MAXLINE+1], recvbuff[MAXLINE+1];
7 /* initialize file descriptor set */
9 maxfd = max(fileno(filein), socket) + 1;
11 FD_SET(socket, &fset); /* set for the socket */
12 FD_SET(fileno(filein), &fset); /* set for the standard input */
13 select(maxfd, &fset, NULL, NULL, NULL); /* wait for read ready */
14 if (FD_ISSET(fileno(filein), &fset)) { /* if ready on stdin */
15 if (fgets(sendbuff, MAXLINE, filein) == NULL) { /* if no input */
16 return; /* we stopped client */
17 } else { /* else we have to write to socket */
18 nwrite = FullWrite(socket, sendbuff, strlen(sendbuff));
19 if (nwrite < 0) { /* on error stop */
20 printf("Errore in scrittura: %s", strerror(errno));
25 if (FD_ISSET(socket, &fset)) { /* if ready on socket */
26 nread = read(socket, recvbuff, strlen(sendbuff)); /* do read */
27 if (nread < 0) { /* error condition, stop client */
28 printf("Errore in lettura: %s\n", strerror(errno));
31 if (nread == 0) { /* server closed connection, stop */
32 printf("EOF sul socket\n");
35 recvbuff[nread] = 0; /* else read is ok, write on stdout */
36 if (fputs(recvbuff, stdout) == EOF) {
37 perror("Errore in scrittura su terminale");