2 #include <samchon/API.hpp> 4 #include <samchon/protocol/ClientDriver.hpp> 48 std::unique_ptr<boost::asio::ip::tcp::acceptor> _Acceptor;
63 if (_Acceptor ==
nullptr || _Acceptor->is_open() ==
false)
74 virtual void open(
int port)
76 if (_Acceptor !=
nullptr && _Acceptor->is_open())
79 boost::asio::io_service io_service;
80 boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), port);
81 boost::system::error_code error;
83 _Acceptor.reset(
new boost::asio::ip::tcp::acceptor(io_service, endpoint));
87 std::shared_ptr<boost::asio::ip::tcp::socket> socket(
new boost::asio::ip::tcp::socket(io_service));
88 _Acceptor->accept(*socket);
93 std::thread(&Server::handle_connection,
this, socket).detach();
102 if (_Acceptor ==
nullptr)
127 virtual void addClient(std::shared_ptr<ClientDriver>) = 0;
130 virtual void handle_connection(std::shared_ptr<boost::asio::ip::tcp::socket> socket)
132 addClient(std::make_shared<ClientDriver>(socket));
virtual void addClient(std::shared_ptr< ClientDriver >)=0
virtual void open(int port)