Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
enriched_storage.cpp
Go to the documentation of this file.
1#include <iostream>
4
5struct connection_data {
6 int sessionid;
7 std::string name;
8};
9
29
32
34using websocketpp::lib::placeholders::_1;
35using websocketpp::lib::placeholders::_2;
36using websocketpp::lib::bind;
37
38class print_server {
39public:
40 print_server() : m_next_sessionid(1) {
41 m_server.init_asio();
42
43 m_server.set_open_handler(bind(&print_server::on_open,this,::_1));
44 m_server.set_close_handler(bind(&print_server::on_close,this,::_1));
45 m_server.set_message_handler(bind(&print_server::on_message,this,::_1,::_2));
46 }
47
49 connection_ptr con = m_server.get_con_from_hdl(hdl);
50
51 con->sessionid = m_next_sessionid++;
52 }
53
55 connection_ptr con = m_server.get_con_from_hdl(hdl);
56
57 std::cout << "Closing connection " << con->name
58 << " with sessionid " << con->sessionid << std::endl;
59 }
60
62 connection_ptr con = m_server.get_con_from_hdl(hdl);
63
64 if (con->name.empty()) {
65 con->name = msg->get_payload();
66 std::cout << "Setting name of connection with sessionid "
67 << con->sessionid << " to " << con->name << std::endl;
68 } else {
69 std::cout << "Got a message from connection " << con->name
70 << " with sessionid " << con->sessionid << std::endl;
71 }
72 }
73
74 void run(uint16_t port) {
75 m_server.listen(port);
76 m_server.start_accept();
77 m_server.run();
78 }
79private:
80 int m_next_sessionid;
81 server m_server;
82};
83
84int main() {
86 server.run(9002);
87}
void on_message(connection_hdl hdl, server::message_ptr msg)
void run(uint16_t port)
void on_close(connection_hdl hdl)
void on_open(connection_hdl hdl)
Concurrency policy that uses std::mutex / boost::mutex.
Definition basic.hpp:37
Stub for user supplied base class.
connection_ptr get_con_from_hdl(connection_hdl hdl, lib::error_code &ec)
Retrieves a connection_ptr from a connection_hdl (exception free)
Definition endpoint.hpp:643
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void set_open_handler(open_handler h)
Definition endpoint.hpp:277
void set_close_handler(close_handler h)
Definition endpoint.hpp:282
Stores, parses, and manipulates HTTP requests.
Definition request.hpp:50
Stores, parses, and manipulates HTTP responses.
Definition response.hpp:57
Basic logger that outputs to an ostream.
Definition basic.hpp:59
Represents a buffer for a single WebSocket message.
Definition pool.hpp:101
Thread safe stub "random" integer generator.
Definition none.hpp:46
Server endpoint role based on the given config.
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
Asio based endpoint transport component.
Definition endpoint.hpp:53
websocketpp::server< custom_config > server
server::connection_ptr connection_ptr
int main()
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
unsigned short uint16_t
Definition stdint.h:125
core::concurrency_type concurrency_type
core::alog_type alog_type
core::endpoint_msg_manager_type endpoint_msg_manager_type
websocketpp::config::asio core
core::elog_type elog_type
core::con_msg_manager_type con_msg_manager_type
core::transport_type transport_type
connection_data connection_base
core::rng_type rng_type
core::request_type request_type
core::message_type message_type
core::response_type response_type
core::endpoint_base endpoint_base
Server config with asio transport and TLS disabled.