218 {
219 bool done = false;
220 std::string input;
222
223 while (!done) {
224 std::cout << "Enter Command: ";
225 std::getline(std::cin, input);
226
227 if (input == "quit") {
228 done = true;
229 } else if (input == "help") {
230 std::cout
231 << "\nCommand List:\n"
232 << "connect <ws uri>\n"
233 << "close <connection id> [<close code:default=1000>] [<close reason>]\n"
234 << "show <connection id>\n"
235 << "help: Display this help text\n"
236 << "quit: Exit the program\n"
237 << std::endl;
238 } else if (input.substr(0,7) == "connect") {
239 int id = endpoint.
connect(input.substr(8));
240 if (id != -1) {
241 std::cout << "> Created connection with id " << id << std::endl;
242 }
243 } else if (input.substr(0,5) == "close") {
244 std::stringstream
ss(input);
245
246 std::string cmd;
248 int close_code = websocketpp::close::status::normal;
249 std::string reason;
250
251 ss >> cmd >>
id >> close_code;
252 std::getline(ss,reason);
253
254 endpoint.
close(
id, close_code, reason);
255 } else if (input.substr(0,4) == "show") {
256 int id = atoi(input.substr(5).c_str());
257
259 if (metadata) {
260 std::cout << *metadata << std::endl;
261 } else {
262 std::cout << "> Unknown connection id " << id << std::endl;
263 }
264 } else {
265 std::cout << "> Unrecognized Command" << std::endl;
266 }
267 }
268
269 return 0;
270}
int connect(std::string const &uri)
connection_metadata::ptr get_metadata(int id) const
void close(int id, websocketpp::close::status::value code, std::string reason)
static const Segment ss(Segment::ss)