#include #include #include #include #include #include #include #include #include #include int main(int argc, char **argv) { int listenfd, connfd; // int port = atoi(argv[1]); int port = 2345; struct sockaddr_in servaddr; char buff[1000]; time_t ticks; listenfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(port); bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)); listen(listenfd, 8); for (;;) { connfd = accept(listenfd, (struct sockaddr *) NULL, NULL); ticks = time(NULL); snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks)); write(connfd, buff, strlen(buff)); close(connfd); } }