| 128 | }; |
| 129 | |
| 130 | int 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 | } |
nothing calls this directly
no test coverage detected