From 3b782e664acc1f665b5bec0a6a994e53532cd528 Mon Sep 17 00:00:00 2001 From: "Simon V. Lejel" Date: Sat, 10 Feb 2024 13:35:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/main.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/client/main.cc diff --git a/src/client/main.cc b/src/client/main.cc new file mode 100644 index 0000000..552bf17 --- /dev/null +++ b/src/client/main.cc @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include + +using std::cout, std::cin, std::endl, std::string; + +int main() { + + struct Message { + char * content; + string username; + }; + + int clientSocket = socket(AF_INET, SOCK_STREAM, 0); + + sockaddr_in serverAdress; + serverAdress.sin_family = AF_INET; + serverAdress.sin_port = htons(8080); + serverAdress.sin_addr.s_addr = inet_addr("127.0.0.50"); + + while (true) { + Message message; + cout << "Type message to server: "; + cin >> message.content; + cout << endl; + message.username = "Client 1"; + + if (strcmp(message.content, "exit") == 0) { + break; + } + + cout << "Sending message to server as user: " << message.username << endl; + send(clientSocket, message.content, strlen(message.content), 0); + } + + close(clientSocket); + + return 0; +}