while (1) { apprentice = master; if (select(maxfd+1, &apprentice, NULL, NULL, NULL) == -1) { output(server, "chat_server()~> select(): couldn't execute select call.\n"); exit(EXIT_FAILURE); } for (x = 0; x <= maxfd; x++) { if (FD_ISSET(&apprentice, x)) { if (x == sockfd) { // Woha, new pplz! sock_len = sizeof(remote); if ((newfd = accept(x, (struct sockaddr *)remote, &sock_len)) == -1) { output(server, "chat_server()~> accept(): wasn't able to stablish new connection!.\n"); exit(EXIT_FAILURE); } else { FD_SET(newfd, &master); if (newfd > maxfd) maxfd = newfd; output(server, "chat_server()~> Connection: new connection from %s @ FD %i.\n", inet_ntoa(remote.sin_addr), newfd); } } else { // Handle data recieving, etc etc etc } } } }