/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Server.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/04/13 22:31:44 by aortigos #+# #+# */ /* Updated: 2026/04/13 22:31:44 by aortigos ### ########.fr */ /* */ /* ************************************************************************** */ #include "Server.hpp" ////////////////// // Constructors // ////////////////// Server::Server() { std::cout << "Server default constructor called" << std::endl; } Server::Server(int port) : port(port) { std::cout << "Server will use port: " << port << std::endl; } Server::~Server() { std::cout << "Server destructor called" << std::endl; } int Server::run() { int server_fd = socket(AF_INET, SOCK_STREAM, 0); sockaddr_in addr = {}; addr.sin_family = AF_INET; addr.sin_port = htons(this->port); addr.sin_addr.s_addr = INADDR_ANY; bind(server_fd, (sockaddr*)&addr, sizeof(addr)); listen(server_fd, 1); std::cout << "Esperando conexion" << std::endl; int client_fd = accept(server_fd, NULL, NULL); std::cout << "Cliente conectado" << std::endl; char buf[512] = {0}; recv(client_fd, buf, sizeof(buf), 0); std::cout << "Mensaje: " << buf << std::endl; close(client_fd); close(server_fd); return (0); }