{
printf("call listen failure!\n");
exit(1);
}
while(1)
{
char buf[BUFFER_SIZE];
long timestamp;
socklen_t length = sizeof(client_addr);
client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_addr, &length);
if(client_sockfd < 0)
{
printf("error comes when call accept!\n");
break;
}
strcpy(buf, WELCOME_MESSAGE);
printf("from client,IP:%s,Port:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
timestamp = time(NULL);
strcat(buf, "timestamp in server:");
strcat(buf, ctime(& timestamp));
send(client_sockfd, buf, BUFFER_SIZE, 0);
close(client_sockfd);
}
close(server_sockfd);
return 0;
}