261 {
262 bool done = false;
263 std::string input;
265
266 while (!done) {
267 std::cout << "Enter Command: ";
268 std::getline(std::cin, input);
269
270 if (input == "quit") {
271 done = true;
272 } else if (input == "help") {
273 std::cout
274 << "\nCommand List:\n"
275 << "connect <ws uri>\n"
276 << "send <connection id> <message>\n"
277 << "close <connection id> [<close code:default=1000>] [<close reason>]\n"
278 << "show <connection id>\n"
279 << "help: Display this help text\n"
280 << "quit: Exit the program\n"
281 << std::endl;
282 } else if (input.substr(0,7) == "connect") {
283 int id = endpoint.
connect(input.substr(8));
284 if (id != -1) {
285 std::cout << "> Created connection with id " << id << std::endl;
286 }
287 } else if (input.substr(0,4) == "send") {
288 std::stringstream
ss(input);
289
290 std::string cmd;
292 std::string message;
293
295 std::getline(ss,message);
296
297 endpoint.
send(
id, message);
298 } else if (input.substr(0,5) == "close") {
299 std::stringstream
ss(input);
300
301 std::string cmd;
303 int close_code = websocketpp::close::status::normal;
304 std::string reason;
305
306 ss >> cmd >>
id >> close_code;
307 std::getline(ss,reason);
308
309 endpoint.
close(
id, close_code, reason);
310 } else if (input.substr(0,4) == "show") {
311 int id = atoi(input.substr(5).c_str());
312
314 if (metadata) {
315 std::cout << *metadata << std::endl;
316 } else {
317 std::cout << "> Unknown connection id " << id << std::endl;
318 }
319 } else {
320 std::cout << "> Unrecognized Command" << std::endl;
321 }
322 }
323
324 return 0;
325}
int connect(std::string const &uri)
connection_metadata::ptr get_metadata(int id) const
void send(int id, std::string message)
void close(int id, websocketpp::close::status::value code, std::string reason)
static const Segment ss(Segment::ss)