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

Function main

example/cpp14/echo/blocking_udp_echo_client.cpp:21–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19enum { max_length = 1024 };
20
21int main(int argc, char* argv[])
22{
23 try
24 {
25 if (argc != 3)
26 {
27 std::cerr << "Usage: blocking_udp_echo_client <host> <port>\n";
28 return 1;
29 }
30
31 boost::asio::io_context io_context;
32
33 udp::socket s(io_context, udp::endpoint(udp::v4(), 0));
34
35 udp::resolver resolver(io_context);
36 udp::endpoint endpoint =
37 *resolver.resolve(udp::v4(), argv[1], argv[2]).begin();
38
39 std::cout << "Enter message: ";
40 char request[max_length];
41 std::cin.getline(request, max_length);
42 size_t request_length = std::strlen(request);
43 s.send_to(boost::asio::buffer(request, request_length), endpoint);
44
45 char reply[max_length];
46 udp::endpoint sender_endpoint;
47 size_t reply_length = s.receive_from(
48 boost::asio::buffer(reply, max_length), sender_endpoint);
49 std::cout << "Reply is: ";
50 std::cout.write(reply, reply_length);
51 std::cout << "\n";
52 }
53 catch (std::exception& e)
54 {
55 std::cerr << "Exception: " << e.what() << "\n";
56 }
57
58 return 0;
59}

Callers

nothing calls this directly

Calls 7

bufferFunction · 0.85
endpointClass · 0.50
beginMethod · 0.45
resolveMethod · 0.45
send_toMethod · 0.45
receive_fromMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected