waits for client requests, then calls time() to get date and time, builds a string containing the answer, writes on the socket and closes the connection.

intconnfd;intn;time_tticks;charbuff[MAXLINE];while(1){if((connfd=accept(listenfd,(structsockaddr*)NULL,NULL))<0){perror("accept");return1;}// Send the time to the client
ticks=time(NULL);snprintf(buff,sizeof(buff),"%.24s\r\n",ctime(&ticks));while((n=write(connfd,buff,strlen(buff)))<0);// Close the connection
close(connfd);}