47 typedef websocketpp::lib::shared_ptr<connection_metadata>
ptr;
52 , m_status(
"Connecting")
61 m_server = con->get_response_header(
"Server");
68 m_server = con->get_response_header(
"Server");
69 m_error_reason = con->get_ec().message();
79 std::string m_error_reason;
83 out <<
"> URI: " << data.m_uri <<
"\n" 84 <<
"> Status: " << data.m_status <<
"\n" 85 <<
"> Remote Server: " << (data.m_server.empty() ?
"None Specified" : data.m_server) <<
"\n" 86 <<
"> Error/close reason: " << (data.m_error_reason.empty() ?
"N/A" : data.m_error_reason);
97 m_endpoint.init_asio();
98 m_endpoint.start_perpetual();
100 m_thread = websocketpp::lib::make_shared<websocketpp::lib::thread>(&
client::run, &m_endpoint);
104 websocketpp::lib::error_code ec;
109 std::cout <<
"> Connect initialization error: " << ec.message() << std::endl;
113 int new_id = m_next_id++;
114 connection_metadata::ptr metadata_ptr = websocketpp::lib::make_shared<connection_metadata>(new_id, con->get_handle(), uri);
115 m_connection_list[new_id] = metadata_ptr;
117 con->set_open_handler(websocketpp::lib::bind(
121 websocketpp::lib::placeholders::_1
123 con->set_fail_handler(websocketpp::lib::bind(
127 websocketpp::lib::placeholders::_1
130 m_endpoint.connect(con);
136 con_list::const_iterator metadata_it = m_connection_list.find(
id);
137 if (metadata_it == m_connection_list.end()) {
140 return metadata_it->second;
144 typedef std::map<int,connection_metadata::ptr> con_list;
147 websocketpp::lib::shared_ptr<websocketpp::lib::thread> m_thread;
149 con_list m_connection_list;
159 std::cout <<
"Enter Command: ";
160 std::getline(std::cin, input);
162 if (input ==
"quit") {
164 }
else if (input ==
"help") {
166 <<
"\nCommand List:\n" 167 <<
"connect <ws uri>\n" 168 <<
"show <connection id>\n" 169 <<
"help: Display this help text\n" 170 <<
"quit: Exit the program\n" 172 }
else if (input.substr(0,7) ==
"connect") {
173 int id = endpoint.
connect(input.substr(8));
175 std::cout <<
"> Created connection with id " <<
id << std::endl;
177 }
else if (input.substr(0,4) ==
"show") {
178 int id = atoi(input.substr(5).c_str());
182 std::cout << *metadata << std::endl;
184 std::cout <<
"> Unknown connection id " <<
id << std::endl;
187 std::cout <<
"> Unrecognized Command" << std::endl;
static level const all
Special aggregate value representing "all levels".
connection_type::ptr connection_ptr
Type of a shared pointer to the connections this server will create.
connection_metadata::ptr get_metadata(int id) const
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
int connect(std::string const &uri)
std::size_t run()
wraps the run method of the internal io_service object
websocketpp::client< websocketpp::config::asio_client > client
static level const all
Special aggregate value representing "all levels".