server sending received to all clients

I shall fix the output lol
This commit is contained in:
Václav Šmejkal 2023-02-22 14:37:18 +01:00
parent c6e98d120a
commit 6e746b020b
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59
2 changed files with 6 additions and 2 deletions

View File

@ -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(">>> ");

View File

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