server sending received to all clients
I shall fix the output lol
This commit is contained in:
parent
c6e98d120a
commit
6e746b020b
@ -26,6 +26,7 @@ int main(void)
|
|||||||
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t line_length = 0;
|
size_t line_length = 0;
|
||||||
|
pthread_t thread_buffer;
|
||||||
|
|
||||||
//DEFINE SERVER ADDRESS
|
//DEFINE SERVER ADDRESS
|
||||||
struct sockaddr_in server_addr;
|
struct sockaddr_in server_addr;
|
||||||
@ -45,6 +46,8 @@ int main(void)
|
|||||||
|
|
||||||
if (connectStatus < 0) why2_die("Connecting failed.");
|
if (connectStatus < 0) why2_die("Connecting failed.");
|
||||||
|
|
||||||
|
pthread_create(&thread_buffer, NULL, why2_listen_server, &listen_socket); //LISTEN TO OTHER USERS
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
printf(">>> ");
|
printf(">>> ");
|
||||||
|
@ -115,7 +115,7 @@ void *send_to_all(void *message)
|
|||||||
|
|
||||||
do //SEND TO ALL CONNECTIONS
|
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;
|
node_buffer = node_buffer -> next;
|
||||||
} while (node_buffer -> next != NULL);
|
} while (node_buffer -> next != NULL);
|
||||||
@ -166,7 +166,8 @@ void *why2_communicate_thread(void *arg)
|
|||||||
|
|
||||||
printf("Received:\n%s\n\n", received);
|
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);
|
why2_deallocate(received);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user