|
程序段节选: int listenfd, connfd, maxfd=0; int nready; fd_set rset, allset; struct sockaddr_in cliaddr, servaddr; int clilen;
listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd > maxfd) maxfd = listenfd;
memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(4321);
bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
FD_ZERO(&allset); FD_SET(listenfd, &allset); listen(listenfd, 10);
/* main loop */ while (1) {
} |