From 4fe82b42b6f6fb1a69da2fb2823831e6b3eaa036 Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sun, 20 Oct 2024 19:40:09 +0200 Subject: Added mvp implementations of the server and client for testing --- server.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'server.c') diff --git a/server.c b/server.c index 675bfb7..06a26b3 100644 --- a/server.c +++ b/server.c @@ -20,10 +20,10 @@ // TODO: send message to all other clients // - implement different rooms // - implement history +// - [ ] fix server copying the bytes correctly // - implement tls #include "common.h" -#include "config.h" #include #include #include @@ -62,17 +62,15 @@ int main(void) const struct sockaddr_in address = { AF_INET, - htons(PORT), + htons(9999), {0}, }; - if (bind(serverfd, (struct sockaddr *)&address, sizeof(address))) { + if (bind(serverfd, (struct sockaddr *)&address, sizeof(address))) err_exit("Error while binding."); - } - if (listen(serverfd, BUF_MAX)) { + if (listen(serverfd, BUF_MAX)) err_exit("Error while listening"); - } writef("Listening on localhost:%d\n", PORT); @@ -144,6 +142,7 @@ int main(void) nclient--; break; } else if (nrecv == -1) { + // TODO: this can happen when connect is reset by pear err_exit("Error while receiving from client socket."); } @@ -160,12 +159,10 @@ int main(void) printf("Retransmitted message to client %d.\n", j); } - // // TODO: check if bytes are correct - // FILE *f = fopen("srv_recv.bin", "wb"); - // fwrite(&msg_recv, sizeof(struct message), 1, f); - // fclose(f); - // - // printf("written %lu bytes to srv_recv.bin\n", sizeof(msg_recv)); + // // TODO: Serialize received message + FILE *f = fopen(filename, "wb"); + save_message(&msg_recv, f); + fclose(f); // return 0; } } -- cgit v1.2.3