First, open the network communication port, choose the TCP protocol
LISTENFD = socket (af_inet,sock_stream,0);
Second, initialize the SERVADDR, and make the network byte sequence conversion
Bzero (&servaddr,sizeof (SERVADDR));
servaddr.sin_family = af_inet;
SERVADDR.SIN_ADDR.S_ADDR = htonl (Inaddr_any);
Servaddr.sin_port = htons (Serv_port);
Third, bind IP and port
Bind (LISTENFD, (struct sockaddr *) &servaddr,sizeof (SERVADDR));
Iv. setting the number of monitoring links
Listen (listenfd,20);
V. Initialize CLIENT[I] to record the file descriptor returned by accept
for (i = 0; i < fd_setsize; i++)
Client[i] =–1;
Vi. Constructing Select monitoring file descriptor set
Fd_zero (&allset);
Fd_set (Listenfd,&allset);
Seven, cyclic blocking listener file descriptor
while (1) {
1. The Select Monitor signal set is newly set in each cycle, and the number of file descriptors ready to be returned by select
RSet = Allset;
Nready = select (Maxfd+1,&rset,null,null,null);
2. Determine whether the file description character Listenfd 1, if yes, process the new link request
if (Fd_isset (Listenfd,&rset)) {
}
3. If not, test which clients has data ready
for (i = 0; I <= maxi; i++) {
}
}