-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
35 lines (29 loc) · 915 Bytes
/
server.cpp
File metadata and controls
35 lines (29 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "server.h"
void session::do_read()
{
auto self(shared_from_this());
socket_.async_read_some(boost::asio::buffer(data_, max_length),
[this, self](boost::system::error_code ec, std::size_t length)
{
if (!ec)
{
tcp::endpoint remote_ep = socket_.remote_endpoint();
std::cout << "\n\tSERVER [CLIENT ID: " << session_id << "]> GET FROM IP: " << remote_ep.address() << "\tDATA:";
std::cout.write(data_, length);
std::cout << std::endl;
do_read();
}
});
}
void server::do_accept()
{
acceptor_.async_accept(
[this](boost::system::error_code ec, tcp::socket socket)
{
if (!ec)
{
std::make_shared<session>(std::move(socket), ++session_id)->start();
}
do_accept();
});
}