From d151c6515cc0bf8da1dce6e82dd8f38de9d28d85 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Thu, 9 Feb 2023 18:25:45 +0100 Subject: [PATCH] looped accepting sockets --- src/chat/server/main.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/chat/server/main.c b/src/chat/server/main.c index 0cd36a2..d1ae596 100644 --- a/src/chat/server/main.c +++ b/src/chat/server/main.c @@ -23,6 +23,8 @@ void die(char *exit_message); int main(void) { int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET + int accepted; + char *received = why2_malloc(SEND_LENGTH); if (listen_socket < 0) die("Failed creating socket."); @@ -38,14 +40,23 @@ int main(void) //LISTEN if (listen(listen_socket, 1) < 0) die("Binding failed."); + //LOOP ACCEPT + while (getchar() != '\n') //END WHEN ENTER IS PRESSED + { + accepted = accept(listen_socket, (SA *) NULL, NULL); + } + + //DEALLOCATION + why2_deallocate(received); + return 0; } void die(char *exit_msg) { - fprintf(stderr, "%s\n", exit_msg); + fprintf(stderr, "%s\n", exit_msg); //ERR MSG - why2_clean_memory(why2_get_default_memory_identifier()); + why2_clean_memory(why2_get_default_memory_identifier()); //GARBAGE COLLECTOR exit(0); } \ No newline at end of file