1 void ClientEcho(FILE * filein, int socket, struct sockaddr_in * serv_addr)
3 char sendbuff[MAXLINE+1], recvbuff[MAXLINE+1];
5 /* initialize file descriptor set */
7 if (fgets(sendbuff, MAXLINE, filein) == NULL) {
8 return; /* if no input just return */
9 } else { /* else we have to write to socket */
10 nwrite = sendto(socket, sendbuff, strlen(sendbuff), 0,
11 (struct sockaddr *) serv_addr, sizeof(*serv_addr));
12 if (nwrite < 0) { /* on error stop */
13 printf("Errore in scrittura: %s", strerror(errno));
17 nread = recvfrom(socket, recvbuff, strlen(sendbuff), 0, NULL, NULL);
18 if (nread < 0) { /* error condition, stop client */
19 printf("Errore in lettura: %s\n", strerror(errno));
22 recvbuff[nread] = 0; /* else read is ok, write on stdout */
23 if (fputs(recvbuff, stdout) == EOF) {
24 perror("Errore in scrittura su terminale");