diff --git a/src/server.c b/src/server.c index 060fc45..882767c 100644 --- a/src/server.c +++ b/src/server.c @@ -93,13 +93,7 @@ int main(int argc, char *argv[]) { } else { printf("received connection from %s\n", ip4tostring(ntohl(client_socket.sin_addr.s_addr))); - /* Create a pipe for message exchange between Dispatcher and ClientSender */ - if (pipe(message_pipe) != 0) { - perror("pipe"); - return EXIT_FAILURE; - } - - /* Create client details */ + /* Get client id to make sure we can handle him */ if ((client_id = get_next_free_client_id()) == -1) { /* Client array is full, refuse connection */ fprintf(stderr, "get_next_free_client_id: Client array must be full\n"); @@ -109,6 +103,12 @@ int main(int argc, char *argv[]) { continue; } + /* Create a pipe for message exchange between Dispatcher and ClientSender */ + if (pipe(message_pipe) != 0) { + perror("pipe"); + return EXIT_FAILURE; + } + /* Start client threads */ if (pthread_create(&clientsender, NULL, ClientSender, &clients[client_id]) != 0) { fprintf(stderr, "pthread_create: error for ClientSender\n");