diff --git a/src/server.c b/src/server.c index 0e054fd..504ce9c 100644 --- a/src/server.c +++ b/src/server.c @@ -73,11 +73,11 @@ int main(void) { } else { printf("received connection from %s\n", ip4tostring(ntohl(client_socket.sin_addr.s_addr))); - if (pthread_create(&clientsender, NULL, ClientSender, NULL) != 0) { + if (pthread_create(&clientsender, NULL, ClientSender, &client_sockid) != 0) { fprintf(stderr, "pthread_create: error for ClientSender\n"); exit(EXIT_FAILURE); } - if (pthread_create(&clientlistener, NULL, ClientListener, NULL) != 0) { + if (pthread_create(&clientlistener, NULL, ClientListener, &client_sockid) != 0) { fprintf(stderr, "pthread_create: error for ClientSender\n"); exit(EXIT_FAILURE); } @@ -97,6 +97,7 @@ void *Dispatcher(void *arg) { /* Thread, listens for incoming messages */ void *ClientListener(void *arg) { + int client_sockid = *((int*) arg); char buf[BUF_LEN]; int n = 0; @@ -116,6 +117,8 @@ void *ClientListener(void *arg) { /* Thread, sends messages to the client */ void *ClientSender(void *arg) { + int client_sockid = *((int*) arg); + pthread_exit(0); }