From 63bd78aeb0a50d9b6588246194129b3c2fd64c48 Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Sat, 10 Feb 2024 14:24:15 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20server=20continous?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/main.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/server/main.cc b/src/server/main.cc index 873c41f..1232f6c 100644 --- a/src/server/main.cc +++ b/src/server/main.cc @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -8,12 +9,7 @@ using std::cout, std::endl, std::string; int main() { - struct Message { - string content; - string username; - }; - - cout << "Initializing server"; + cout << "Initializing server" << endl; int serverSocket = socket(AF_INET, SOCK_STREAM, 0); if (serverSocket == -1) { // TODO error @@ -40,9 +36,11 @@ int main() { // TODO error } - char buffer[1024] = { 0 }; - recv(clientSocket, buffer, sizeof(buffer), 0); - cout << "Message from client " << buffer << endl; + while (true) { + char buffer[1024] = {0}; + recv(clientSocket, buffer, sizeof(buffer), 0); + cout << buffer << endl; + } close(serverSocket);