From 6e746b020b6d3efcc4d28e52e981464765d2539a Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 22 Feb 2023 14:37:18 +0100 Subject: [PATCH] server sending received to all clients I shall fix the output lol --- src/chat/main/client.c | 3 +++ src/chat/misc.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/chat/main/client.c b/src/chat/main/client.c index bf5d4c7..1ff0322 100644 --- a/src/chat/main/client.c +++ b/src/chat/main/client.c @@ -26,6 +26,7 @@ int main(void) int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET char *line = NULL; size_t line_length = 0; + pthread_t thread_buffer; //DEFINE SERVER ADDRESS struct sockaddr_in server_addr; @@ -45,6 +46,8 @@ int main(void) if (connectStatus < 0) why2_die("Connecting failed."); + pthread_create(&thread_buffer, NULL, why2_listen_server, &listen_socket); //LISTEN TO OTHER USERS + for (;;) { printf(">>> "); diff --git a/src/chat/misc.c b/src/chat/misc.c index f5189ab..378aac4 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -115,7 +115,7 @@ void *send_to_all(void *message) do //SEND TO ALL CONNECTIONS { - why2_send_socket(*((char**) message), node_buffer -> connection); //SEND TO CLIENT + why2_send_socket((char*) message, node_buffer -> connection); //SEND TO CLIENT node_buffer = node_buffer -> next; } while (node_buffer -> next != NULL); @@ -166,7 +166,8 @@ void *why2_communicate_thread(void *arg) printf("Received:\n%s\n\n", received); - pthread_create(&thread_buffer, NULL, send_to_all, &received); + pthread_create(&thread_buffer, NULL, send_to_all, received); + pthread_join(thread_buffer, NULL); why2_deallocate(received); }