Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
step5.cpp File Reference
#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>
#include <websocketpp/common/thread.hpp>
#include <websocketpp/common/memory.hpp>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <sstream>
Include dependency graph for step5.cpp:

Go to the source code of this file.

Classes

class  connection_metadata
 
class  websocket_endpoint
 

Typedefs

typedef websocketpp::client< websocketpp::config::asio_clientclient
 

Functions

std::ostream & operator<< (std::ostream &out, connection_metadata const &data)
 
int main ()
 

Typedef Documentation

◆ client

Function Documentation

◆ main()

int main ( void )

Definition at line 218 of file step5.cpp.

218 {
219 bool done = false;
220 std::string input;
221 websocket_endpoint endpoint;
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;
247 int id;
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
258 connection_metadata::ptr metadata = endpoint.get_metadata(id);
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}
websocketpp::lib::shared_ptr< connection_metadata > ptr
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)
uint64_t id
Definition code_cache.cpp:0
static const Segment ss(Segment::ss)
Here is the call graph for this function:

◆ operator<<()

std::ostream & operator<< ( std::ostream & out,
connection_metadata const & data )

Definition at line 104 of file step5.cpp.

104 {
105 out << "> URI: " << data.m_uri << "\n"
106 << "> Status: " << data.m_status << "\n"
107 << "> Remote Server: " << (data.m_server.empty() ? "None Specified" : data.m_server) << "\n"
108 << "> Error/close reason: " << (data.m_error_reason.empty() ? "N/A" : data.m_error_reason);
109
110 return out;
111}