sending received message to all clients

This commit is contained in:
Václav Šmejkal 2023-02-22 12:07:26 +01:00
parent 58d5c7ede8
commit 0a331e97a8
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59

View File

@ -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);
}