MCPcopy Create free account
hub / github.com/boostorg/asio / main

Function main

example/cpp11/tutorial/daytime4/client.cpp:17–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
27 boost::asio::io_context io_context;
28
29 udp::resolver resolver(io_context);
30 udp::endpoint receiver_endpoint =
31 *resolver.resolve(udp::v4(), argv[1], "daytime").begin();
32
33 udp::socket socket(io_context);
34 socket.open(udp::v4());
35
36 std::array<char, 1> send_buf = {{ 0 }};
37 socket.send_to(boost::asio::buffer(send_buf), receiver_endpoint);
38
39 std::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}

Callers

nothing calls this directly

Calls 8

bufferFunction · 0.85
beginMethod · 0.45
resolveMethod · 0.45
openMethod · 0.45
send_toMethod · 0.45
receive_fromMethod · 0.45
writeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected