-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.cpp
25 lines (23 loc) · 820 Bytes
/
client.cpp
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
#include <array>
#include <iostream>
#include <boost/array.hpp>
#include <boost/asio.hpp>
#include <string>
using boost::asio::ip::tcp;
int main(int argc, char* argv[])
{
boost::asio::io_service io_service;
tcp::resolver resolver(io_service);
tcp::resolver::query query("192.168.1.86", "9876");
tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
tcp::socket socket(io_service);
boost::asio::connect(socket, endpoint_iterator);
boost::system::error_code error;
std::string my_name = "Zheng Lv";
boost::asio::write(socket, boost::asio::buffer(my_name), error);
std::array<char, 256> input_buffer;
std::size_t rsize = socket.read_some(
boost::asio::buffer(input_buffer), error);
std::cout << std::string(input_buffer.data(), input_buffer.data() + rsize) << std::endl;
return 0;
}