From 1bcbee1c36fd4f0cfcbb7444494ebd3e3525bac9 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Tue, 6 Sep 2022 17:21:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B1=D0=B0=D0=B9=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B5=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B2=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8=20chat()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lesson_03/header/server.hpp | 3 ++- lesson_03/source/server.cpp | 30 +++++++++++------------------- 2 files changed, 13 insertions(+), 20 deletions(-) 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; } }