The accept() system call initiates communications between a connection-oriented server and the client.
int accept(int sockfd, struct sockaddr *cli_addr, int addrlen);
Generally programs call accept() inside an infinite loop, forking a new process for each accepted connection. After accept() returns with client address, the server is ready to accept data.
for( ; ; ) { newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr)); if (fork() = 0) { close(sockfd); /* * read and write data over the network * (code missing) */ exit (0); } close(newsockfd); }