R-Type
TcpServer.hpp
Go to the documentation of this file.
1 /*
2 ** EPITECH PROJECT, 2023
3 ** TcpServer.hpp
4 ** File description:
5 ** TcpServer
6 */
7 
8 #ifndef TCPSERVER_HPP_
9 #define TCPSERVER_HPP_
10 
11 #include "ClientSession.hpp"
12 #include "SafeQueue.hpp"
13 #include <asio.hpp>
14 #include <iostream>
15 #include <thread>
16 
17 namespace RType::Server
18 {
20  class TcpServer
21  {
22  public:
23  TcpServer(asio::io_context &IOContext, int port);
24  ~TcpServer();
25 
26  void run();
27 
28  protected:
29  private:
32  void accept(std::shared_ptr<ClientSession> clientSession);
33 
37  void handleAccept(std::shared_ptr<ClientSession> clientSession, const asio::error_code &error);
38 
39  asio::ip::tcp::acceptor _acceptor;
40  asio::ip::tcp::socket _socket;
41  asio::io_context &_IOContext;
42  asio::ip::tcp::endpoint _clientEndpoint;
43  std::size_t count;
44  std::vector<std::shared_ptr<ClientSession>> _clients;
45  };
46 } // namespace RType::Server
47 
48 #endif /* !TCPSERVER_HPP_ */
This class manages all the TCP server event from clients.
Definition: TcpServer.hpp:21
~TcpServer()
Definition: TcpServer.cpp:16
void run()
Definition: TcpServer.cpp:38
TcpServer(asio::io_context &IOContext, int port)
Definition: TcpServer.cpp:10
Definition: ClientSession.hpp:16