KlassischeKeplerKriege/game/server.hpp

40 lines
649 B
C++
Raw Normal View History

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