Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
external_io_service.cpp File Reference
#include "tcp_echo_server.hpp"
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
Include dependency graph for external_io_service.cpp:

Go to the source code of this file.

Typedefs

typedef websocketpp::server< websocketpp::config::asiows_echo_server
 

Functions

void on_message (ws_echo_server *s, websocketpp::connection_hdl hdl, ws_echo_server::message_ptr msg)
 
int main ()
 

Typedef Documentation

◆ ws_echo_server

Function Documentation

◆ main()

int main ( void )

Definition at line 61 of file external_io_service.cpp.

61 {
62 asio::io_service service;
63
64 // Add a TCP echo server on port 9003
65 tcp_echo_server custom_http_server(service, 9003);
66
67 // Add a WebSocket echo server on port 9002
68 ws_echo_server ws_server;
71
72 // The only difference in this code between an internal and external
73 // io_service is the different constructor to init_asio
74 ws_server.init_asio(&service);
75
76 // Register our message handler
77 ws_server.set_message_handler(bind(&on_message,&ws_server,::_1,::_2));
78 ws_server.listen(9002);
79 ws_server.start_accept();
80
81 // TODO: add a timer?
82
83 // Start the Asio io_service run loop for all
84 service.run();
85}
void set_message_handler(message_handler h)
Definition endpoint.hpp:322
void clear_access_channels(log::level channels)
Clear Access logging channels.
Definition endpoint.hpp:231
void set_access_channels(log::level channels)
Set Access logging channel.
Definition endpoint.hpp:220
void start_accept(lib::error_code &ec)
Starts the server's async connection acceptance loop (exception free)
void on_message(ws_echo_server *s, websocketpp::connection_hdl hdl, ws_echo_server::message_ptr msg)
static level const all
Special aggregate value representing "all levels".
Definition levels.hpp:152
static level const frame_payload
One line per frame, includes the full message payload (warning: chatty)
Definition levels.hpp:129
Here is the call graph for this function:

◆ on_message()

Definition at line 41 of file external_io_service.cpp.

41 {
42 std::cout << "on_message called with hdl: " << hdl.lock().get()
43 << " and message: " << msg->get_payload()
44 << std::endl;
45
46 // check for a special command to instruct the server to stop listening so
47 // it can be cleanly exited.
48 if (msg->get_payload() == "stop-listening") {
49 s->stop_listening();
50 return;
51 }
52
53 try {
54 s->send(hdl, msg->get_payload(), msg->get_opcode());
55 } catch (websocketpp::lib::error_code const & e) {
56 std::cout << "Echo failed because: " << e
57 << "(" << e.message() << ")" << std::endl;
58 }
59}
char * s
Here is the caller graph for this function: