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

Function main

example/cpp11/timeouts/blocking_tcp_client.cpp:152–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

150//----------------------------------------------------------------------
151
152int main(int argc, char* argv[])
153{
154 try
155 {
156 if (argc != 4)
157 {
158 std::cerr << "Usage: blocking_tcp_client <host> <port> <message>\n";
159 return 1;
160 }
161
162 client c;
163 c.connect(argv[1], argv[2], std::chrono::seconds(10));
164
165 auto time_sent = std::chrono::steady_clock::now();
166
167 c.write_line(argv[3], std::chrono::seconds(10));
168
169 for (;;)
170 {
171 std::string line = c.read_line(std::chrono::seconds(10));
172
173 // Keep going until we get back the line that was sent.
174 if (line == argv[3])
175 break;
176 }
177
178 auto time_received = std::chrono::steady_clock::now();
179
180 std::cout << "Round trip time: ";
181 std::cout << std::chrono::duration_cast<
182 std::chrono::microseconds>(
183 time_received - time_sent).count();
184 std::cout << " microseconds\n";
185 }
186 catch (std::exception& e)
187 {
188 std::cerr << "Exception: " << e.what() << "\n";
189 }
190
191 return 0;
192}

Callers

nothing calls this directly

Calls 5

nowFunction · 0.50
connectMethod · 0.45
write_lineMethod · 0.45
read_lineMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected