]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/asio/example/cpp03/tutorial/daytime4/client.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / asio / example / cpp03 / tutorial / daytime4 / client.cpp
CommitLineData
7c673cae
FG
1//
2// client.cpp
3// ~~~~~~~~~~
4//
b32b8144 5// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7c673cae
FG
6//
7// Distributed under the Boost Software License, Version 1.0. (See accompanying
8// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9//
10
11#include <iostream>
12#include <boost/array.hpp>
13#include <boost/asio.hpp>
14
15using boost::asio::ip::udp;
16
17int main(int argc, char* argv[])
18{
19 try
20 {
21 if (argc != 2)
22 {
23 std::cerr << "Usage: client <host>" << std::endl;
24 return 1;
25 }
26
b32b8144 27 boost::asio::io_context io_context;
7c673cae 28
b32b8144
FG
29 udp::resolver resolver(io_context);
30 udp::endpoint receiver_endpoint =
31 *resolver.resolve(udp::v4(), argv[1], "daytime").begin();
7c673cae 32
b32b8144 33 udp::socket socket(io_context);
7c673cae
FG
34 socket.open(udp::v4());
35
36 boost::array<char, 1> send_buf = {{ 0 }};
37 socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint);
38
39 boost::array<char, 128> recv_buf;
40 udp::endpoint sender_endpoint;
41 size_t len = socket.receive_from(
42 boost::asio::buffer(recv_buf), sender_endpoint);
43
44 std::cout.write(recv_buf.data(), len);
45 }
46 catch (std::exception& e)
47 {
48 std::cerr << e.what() << std::endl;
49 }
50
51 return 0;
52}