KlassischeKeplerKriege/game/server.hpp

39 lines
649 B
C++

#pragma once
//#include <iostream>
//#include <memory>
//#include <utility>
#include <asio.hpp>
#include "session.hpp"
using asio::ip::tcp;
class Server
{
public:
Server(asio::io_service& io_service, short port)
: acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
socket_(io_service)
{
do_accept();
}
private:
void do_accept()
{
acceptor_.async_accept(socket_,
[this](std::error_code ec)
{
if (!ec)
{
std::make_shared<Session>(std::move(socket_))->start();
}
do_accept();
});
}
tcp::acceptor acceptor_;
tcp::socket socket_;
};