From 0a331e97a85d87caeaa9b55c0c3fbc0cfd0afc67 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 22 Feb 2023 12:07:26 +0100 Subject: [PATCH] sending received message to all clients --- src/chat/misc.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/chat/misc.c b/src/chat/misc.c index be1e481..9fca1d7 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -107,6 +107,22 @@ node_t *get_node(int connection) return buffer; } +void *send_to_all(void *message) +{ + if (head == NULL) return NULL; + + node_t *node_buffer = head; + + do //SEND TO ALL CONNECTIONS + { + why2_send_socket(*((char**) message), node_buffer -> connection); //SEND TO CLIENT + + node_buffer = node_buffer -> next; + } while (node_buffer -> next != NULL); + + return NULL; +} + //GLOBAL void why2_send_socket(char *text, int socket) { @@ -138,6 +154,7 @@ void *why2_communicate_thread(void *arg) const time_t startTime = time(NULL); char *received = NULL; + pthread_t thread_buffer; while (time(NULL) - startTime < 86400) //KEEP COMMUNICATION ALIVE FOR 24 HOURS { @@ -149,6 +166,8 @@ void *why2_communicate_thread(void *arg) printf("Received:\n%s\n\n", received); + pthread_create(&thread_buffer, NULL, send_to_all, &received); + why2_deallocate(received); }