while(fgets(buf,MAXLINE,stdin)!=NULL)
{
write(sockfd,buf,strlen(buf));
n=read(sockfd,buf,MAXLINE);
if(n==0) printf("the other side has been closed.\n");
else write(STDOUT_FILENO,buf,n);
}
/*这一个死循环的作用是使服务器响应客户端的多次输入并进行处理*/
while(1){
n = read(connfd, buf, MAXLINE);
if(n==0){
printf("the other side has been closed.\n");
break;}
printf("received from %s at PORT %d\n",inet_ntop(AF_INET, &cliaddr.sin_addr, str, sizeof(str)),ntohs(cliaddr.sin_port));
for (i = 0; i < n; i++)
buf[i] = toupper(buf[i]);
write(connfd, buf, n);
}
close(connfd);
}
}
#include <stdlib.h>
#include <errno.h>
#include <sys/socket.h>
void perr_exit(const char *s)
{
perror(s);
exit(1);
}
int Accept(int fd, struct sockaddr *sa, socklen_t *salenptr)