From 368c57c2859501195fee69fe41ac7bf3278b4bd0 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Mon, 20 Feb 2023 14:12:26 +0100 Subject: [PATCH] looped client sending && TODOs --- src/chat/client/main.c | 14 ++++++++++++-- src/chat/server/main.c | 4 ++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/chat/client/main.c b/src/chat/client/main.c index a6e3f9e..e4b2722 100644 --- a/src/chat/client/main.c +++ b/src/chat/client/main.c @@ -23,19 +23,29 @@ void send_socket(char *text, int socket); int main(void) { int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET + char *line = NULL; + size_t line_length = 0; //DEFINE SERVER ADDRESS struct sockaddr_in server_addr; server_addr.sin_family = AF_INET; server_addr.sin_port = htons(SERVER_PORT); - server_addr.sin_addr.s_addr = INADDR_ANY; int connectStatus = connect(listen_socket, (SA *) &server_addr, sizeof(server_addr)); //CONNECT if (connectStatus < 0) why2_die("Connecting failed."); - send_socket("123456789123456789", listen_socket); + for (;;) + { + printf(">>> "); + getline(&line, &line_length, stdin); + printf("%s\n", line); + + send_socket(line, listen_socket); + } + + free(line); //TODO: Unreachable; add exit return 0; } diff --git a/src/chat/server/main.c b/src/chat/server/main.c index 667ae1a..1bd5144 100644 --- a/src/chat/server/main.c +++ b/src/chat/server/main.c @@ -43,11 +43,11 @@ int main(void) //LOOP ACCEPT for (;;) { - accepted = accept(listen_socket, (SA *) NULL, NULL); //ACCEPT NEW SOCKET //TODO: CLOSE + accepted = accept(listen_socket, (SA *) NULL, NULL); //ACCEPT NEW SOCKET //TODO: CLOSE (not only this one) if (accepted == -1) why2_die("Accepting socket failed!"); - received = read_socket(accepted); + received = read_socket(accepted); //TODO: Add multithreading if (received == NULL) continue; //FAILED