diff --git a/lesson_03/header/server.hpp b/lesson_03/header/server.hpp index 5b1f24c..9611474 100644 --- a/lesson_03/header/server.hpp +++ b/lesson_03/header/server.hpp @@ -39,7 +39,7 @@ class ServerTCP: public Server // @suppress("Class has a virtual method and non- private: bool _bind; const unsigned short int _sizeBuffer; - std::unique_ptr _buffer; + std::unique_ptr _buffer; class Hook { @@ -54,6 +54,7 @@ private: std::vector _hooks; void chat(); + void readData(const int sizeData); public: ServerTCP(const unsigned short int port, const unsigned short int sizeBuffer = 1024); void bind(); diff --git a/lesson_03/source/server.cpp b/lesson_03/source/server.cpp index 9872b01..40fd8f8 100644 --- a/lesson_03/source/server.cpp +++ b/lesson_03/source/server.cpp @@ -8,12 +8,11 @@ #include #include #include +#include namespace zh { -#define MAX 1024 - Server::Server(const unsigned short int port) : _port(port), _connfd(-1) { _sizeClient = sizeof(*_client); @@ -48,7 +47,7 @@ ServerTCP::ServerTCP(const unsigned short int port, const unsigned short int siz { _socket = std::make_unique(AF_INET, SOCK_STREAM, IPPROTO_IP); _local = std::make_unique
(AF_INET, INADDR_ANY, port); - _buffer = std::make_unique(sizeBuffer); + _buffer = std::make_unique(sizeBuffer); } void ServerTCP::bind() @@ -86,27 +85,20 @@ void ServerTCP::listen() } } +void ServerTCP::readData(const int sizeData) +{ + +} + void ServerTCP::chat() { -// char buff[MAX]; -// int n; while (true) { -// bzero(buff, sizeof(buff)); -// printf("Enter the string : "); -// n = 0; -// while ((buff[n++] = getchar()) != '\n') -// ; -// write(_connfd, buff, sizeof(buff)); bzero(_buffer.get(), _sizeBuffer); - read(_connfd, _buffer.get(), _sizeBuffer); - std::cout << _buffer.get() << std::endl; -// printf("From Server : %s", *_buffer); -// if ((strncmp((*_buffer), "exit", 4)) == 0) -// { -// printf("Client Exit...\n"); -// break; -// } + read(_connfd, _buffer.get(), 4); + std::cout << *reinterpret_cast(_buffer.get()) << std::endl; + close(_connfd); + break; } }