From 0c29c50e2354e57e5a959a63396d8e0e6cb4321c Mon Sep 17 00:00:00 2001 From: iherman- <200969603+iherman-p@users.noreply.github.com> Date: Thu, 7 May 2026 13:01:57 +0200 Subject: [PATCH 1/3] Created a functional basic constructor for Server class --- Server/Server.cpp | 44 +++++++++++++++++++++++++++++++++++--------- Server/Server.hpp | 16 +++++++++++++--- main.cpp | 3 ++- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/Server/Server.cpp b/Server/Server.cpp index 47b424a..7d954a1 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -6,36 +6,62 @@ /* By: iherman- 65535) + if (port_ < 1 || port_ > 65535) throw std::runtime_error("Invalid port"); - std::cout << "Server port: " << port << "\nServer Password: " << password << std::endl; + if (password_.empty()) + throw std::runtime_error("Empty password"); + + serverSocket_ = socket(AF_INET, SOCK_STREAM, 0); + if (serverSocket_ < 0) + throw std::runtime_error("Failed to create socket"); + + struct sockaddr_in addr; + std::memset(&addr, 0, sizeof(addr)); + + addr.sin_family = AF_INET; + addr.sin_port = htons(port_); + addr.sin_addr.s_addr = INADDR_ANY; + + bind(serverSocket_, (struct sockaddr*)&addr, sizeof(addr)); + + std::cout << "Server port: " << port_ + << "\nServer Password: " << password_ + << std::endl; } Server::~Server() { - + close(serverSocket_); } Server &Server::operator=(const Server& other) { if (this != &other) { - std::cout << "operator= called" << std::endl; + port_ = other.port_; + serverSocket_ = other.serverSocket_; + password_ = other.password_; } return *this; -} \ No newline at end of file +} diff --git a/Server/Server.hpp b/Server/Server.hpp index ddb87fa..09e9749 100644 --- a/Server/Server.hpp +++ b/Server/Server.hpp @@ -6,7 +6,7 @@ /* By: iherman- // C++ lib functions -#include +# include # include -# include +# include + +# define PORT_DEFAULT 9898 class Server { private: + static const int kConnectionQueueLimit; + + int port_; + int serverSocket_; + + std::string password_; public: Server(); @@ -48,6 +56,8 @@ class Server ~Server(); Server &operator=(const Server& other); + + void run(); }; #endif // SERVER_HPP \ No newline at end of file diff --git a/main.cpp b/main.cpp index 8a2144d..077974f 100644 --- a/main.cpp +++ b/main.cpp @@ -6,11 +6,12 @@ /* By: iherman- int get_port(const char* arg) { From 4beabead01e0308c63ac2bcd6f136b2ea4eb7be0 Mon Sep 17 00:00:00 2001 From: iherman- <200969603+iherman-p@users.noreply.github.com> Date: Thu, 7 May 2026 13:52:42 +0200 Subject: [PATCH 2/3] Added a basic Server::run function which listens for one connection and sends the data back, added listen call to server constructor --- Server/Server.cpp | 31 +++++++++++++++++++++++++++++-- Server/Server.hpp | 2 +- main.cpp | 5 ++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Server/Server.cpp b/Server/Server.cpp index 7d954a1..39eecc9 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -6,7 +6,7 @@ /* By: iherman- Date: Thu, 7 May 2026 14:18:52 +0200 Subject: [PATCH 3/3] Improved Server::run to now properly handle multiple packets --- Server/Server.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Server/Server.cpp b/Server/Server.cpp index 39eecc9..9f982cb 100644 --- a/Server/Server.cpp +++ b/Server/Server.cpp @@ -6,7 +6,7 @@ /* By: iherman-