#include #include #include #include #include int readline(int fd,char *ptr, int maxlen); int main() { char ptr[512]; char *t; char cpid[25]; //child process number char[] char c; int pid; int sockfd, newsockfd, clilen, childpid, rc, n,i; struct sockaddr_in cli_addr, serv_addr; t=ptr; n=0; if((sockfd = socket(AF_INET,SOCK_STREAM,0))<0) perror("socket error"); bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(5000); if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))<0) perror("bind error"); listen(sockfd, 5); for(;;){ clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if(newsockfd<0) perror("accept error"); if((childpid = fork())<0) perror("fork error"); else if(childpid == 0){ n = 0; n = readline(newsockfd,ptr,512); printf("%s\n",ptr); write(newsockfd,t,n); } } return 0; } int readline(int fd,char *ptr, int maxlen){ int i; int rc; char c; for(i=1;i