Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
scratch_server.cpp
Go to the documentation of this file.
1
6#include <iostream>
7
10
12
15 typedef debug_core base;
16
17 typedef base::concurrency_type concurrency_type;
18
19 typedef base::request_type request_type;
20 typedef base::response_type response_type;
21
22 typedef base::message_type message_type;
23 typedef base::con_msg_manager_type con_msg_manager_type;
24 typedef base::endpoint_msg_manager_type endpoint_msg_manager_type;
25
26 typedef base::alog_type alog_type;
27 typedef base::elog_type elog_type;
28
29 typedef base::rng_type rng_type;
30
31 struct transport_config : public base::transport_config {
39 };
40
43
46
49};
50
52
54
55// Define a callback to handle incoming messages
57 /*std::cout << "on_message called with hdl: " << hdl.lock().get()
58 << " and message (" << msg->get_payload().size() << "): " << msg->get_payload()
59 << std::endl;
60 */
61 try {
62 s->send(hdl, msg->get_payload(), msg->get_opcode());
63 } catch (const websocketpp::lib::error_code& e) {
64 std::cout << "Echo failed because: " << e
65 << "(" << e.message() << ")" << std::endl;
66 }
67}
68
69int main(int argc, char * argv[]) {
70 // Create a server endpoint
71 server echo_server;
72
73 try {
74 // Set logging settings
75 if (argc > 1 && std::string(argv[1]) == "-d") {
78 } else {
81 }
82
83 // Initialize ASIO
84 echo_server.init_asio();
85
86 // Register our message handler
87 using websocketpp::lib::placeholders::_1;
88 using websocketpp::lib::placeholders::_2;
89 echo_server.set_message_handler(bind(&on_message,&echo_server,_1,_2));
90
91 // Listen on port 9002
92 echo_server.listen(9002);
93
94 // Start the server accept loop
95 echo_server.start_accept();
96
97 // Start the ASIO io_service run loop
98 echo_server.run();
99 } catch (const std::exception & e) {
100 std::cout << e.what() << std::endl;
101 } catch (websocketpp::lib::error_code e) {
102 std::cout << e.message() << std::endl;
103 } catch (...) {
104 std::cout << "other exception" << std::endl;
105 }
106}
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void set_access_channels(log::level channels)
Set Access logging channel.
Definition endpoint.hpp:220
void set_error_channels(log::level channels)
Set Error logging channel.
Definition endpoint.hpp:242
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)
Basic ASIO endpoint socket component.
Definition none.hpp:314
Asio based endpoint transport component.
Definition endpoint.hpp:53
websocketpp::config::asio_tls_client::message_type::ptr message_ptr
char ** argv
lib::weak_ptr< void > connection_hdl
A handle to uniquely identify a connection.
websocketpp::server< deflate_config > server
void on_message(server *s, websocketpp::connection_hdl hdl, message_ptr msg)
type::concurrency_type concurrency_type
websocketpp::transport::asio::basic_socket::endpoint socket_type
base::concurrency_type concurrency_type
websocketpp::transport::asio::endpoint< transport_config > transport_type
base::elog_type elog_type
base::con_msg_manager_type con_msg_manager_type
base::endpoint_msg_manager_type endpoint_msg_manager_type
websocketpp::extensions::permessage_deflate::enabled< permessage_deflate_config > permessage_deflate_type
base::rng_type rng_type
base::alog_type alog_type
base::request_type request_type
base::response_type response_type
base::message_type message_type
deflate_config type
Client/Server debug config with iostream transport.
Definition debug.hpp:68
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:114
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:80
static level const none
Special aggregate value representing "no levels".
Definition levels.hpp:61
char * s