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

Function main

example/cpp11/chat/chat_client.cpp:130–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128};
129
130int main(int argc, char* argv[])
131{
132 try
133 {
134 if (argc != 3)
135 {
136 std::cerr << "Usage: chat_client <host> <port>\n";
137 return 1;
138 }
139
140 boost::asio::io_context io_context;
141
142 tcp::resolver resolver(io_context);
143 auto endpoints = resolver.resolve(argv[1], argv[2]);
144 chat_client c(io_context, endpoints);
145
146 std::thread t([&io_context](){ io_context.run(); });
147
148 char line[chat_message::max_body_length + 1];
149 while (std::cin.getline(line, chat_message::max_body_length + 1))
150 {
151 chat_message msg;
152 msg.body_length(std::strlen(line));
153 std::memcpy(msg.body(), line, msg.body_length());
154 msg.encode_header();
155 c.write(msg);
156 }
157
158 c.close();
159 t.join();
160 }
161 catch (std::exception& e)
162 {
163 std::cerr << "Exception: " << e.what() << "\n";
164 }
165
166 return 0;
167}

Callers

nothing calls this directly

Calls 8

body_lengthMethod · 0.80
bodyMethod · 0.80
encode_headerMethod · 0.80
resolveMethod · 0.45
runMethod · 0.45
writeMethod · 0.45
closeMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected