38 lines
642 B
C++
38 lines
642 B
C++
#pragma once
|
|
|
|
#include <asio.hpp>
|
|
|
|
#include "session.hpp"
|
|
|
|
using asio::ip::tcp;
|
|
|
|
class Server
|
|
{
|
|
public:
|
|
Server(asio::io_service& io_service,game::State* s, short port)
|
|
: acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
|
|
socket_(io_service)
|
|
{
|
|
state=s;
|
|
do_accept();
|
|
}
|
|
|
|
private:
|
|
void do_accept()
|
|
{
|
|
acceptor_.async_accept(socket_,
|
|
[this](std::error_code ec)
|
|
{
|
|
if (!ec)
|
|
{
|
|
std::make_shared<Session>(std::move(socket_),state)->start();
|
|
}
|
|
|
|
do_accept();
|
|
});
|
|
}
|
|
|
|
tcp::acceptor acceptor_;
|
|
tcp::socket socket_;
|
|
game::State* state;
|
|
};
|