Побайтовое чтение в функции chat()
This commit is contained in:
parent
550cf32e27
commit
1bcbee1c36
|
@ -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<char[]> _buffer;
|
||||
std::unique_ptr<std::byte[]> _buffer;
|
||||
|
||||
class Hook
|
||||
{
|
||||
|
@ -54,6 +54,7 @@ private:
|
|||
std::vector<Hook> _hooks;
|
||||
|
||||
void chat();
|
||||
void readData(const int sizeData);
|
||||
public:
|
||||
ServerTCP(const unsigned short int port, const unsigned short int sizeBuffer = 1024);
|
||||
void bind();
|
||||
|
|
|
@ -8,12 +8,11 @@
|
|||
#include <server.hpp>
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
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<Socket>(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
||||
_local = std::make_unique<Address>(AF_INET, INADDR_ANY, port);
|
||||
_buffer = std::make_unique<char[]>(sizeBuffer);
|
||||
_buffer = std::make_unique<std::byte[]>(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<int*>(_buffer.get()) << std::endl;
|
||||
close(_connfd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue