-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.h
More file actions
44 lines (36 loc) · 801 Bytes
/
client.h
File metadata and controls
44 lines (36 loc) · 801 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
36
37
38
39
40
41
42
43
44
#pragma once
#include <iostream>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
class client
{
public:
client() :
socket_(io_service),
resolver(io_service),
request_length(0)
{
}
void ConnectToServer(const std::string& host, const std::string& port);
void Send(const std::vector<std::string>& message);
~client() noexcept
{
boost::system::error_code ec;
if (socket_.is_open())
{
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
socket_.close(ec);
if (ec) {
std::cerr << "Close socket error: " << ec.message() << std::endl;
}
}
}
private:
enum { max_length = 1024 };
boost::asio::io_service io_service;
tcp::socket socket_;
tcp::resolver resolver;
tcp::endpoint ep;
char request[max_length] = {0};
size_t request_length;
};