BVB Source Codes

uWebSockets Show wsPP.cpp Source code

Return Download uWebSockets: download wsPP.cpp Source code - Download uWebSockets Source code - Type:.cpp
  1. #include <websocketpp/config/asio_no_tls.hpp>
  2. #include <websocketpp/server.hpp>
  3. #include <iostream>
  4.  
  5. typedef websocketpp::server<websocketpp::config::asio> server;
  6.  
  7. using websocketpp::lib::placeholders::_1;
  8. using websocketpp::lib::placeholders::_2;
  9. using websocketpp::lib::bind;
  10.  
  11. // pull out the type of messages sent by our config
  12. typedef server::message_ptr message_ptr;
  13.  
  14. // Define a callback to handle incoming messages
  15. void on_message(server* s, websocketpp::connection_hdl hdl, message_ptr msg) {
  16.     try {
  17.         s->send(hdl, msg->get_payload(), msg->get_opcode());
  18.     } catch (const websocketpp::lib::error_code& e) {
  19.  
  20.     }
  21. }
  22.  
  23. int main() {
  24.     // Create a server endpoint
  25.     server echo_server;
  26.  
  27.     // 100mb max (used in huge throughput test)
  28.     echo_server.set_max_message_size(1024 * 1024 * 100);
  29.  
  30.     try {
  31.         // Set logging settings
  32.         echo_server.set_access_channels(websocketpp::log::alevel::none);
  33.         echo_server.clear_access_channels(websocketpp::log::alevel::frame_payload);
  34.  
  35.         // Initialize Asio
  36.         echo_server.init_asio();
  37.  
  38.         // Register our message handler
  39.         echo_server.set_message_handler(bind(&on_message,&echo_server,::_1,::_2));
  40.  
  41.         // Listen on port 9002
  42.         echo_server.listen(3000);
  43.  
  44.         // Start the server accept loop
  45.         echo_server.start_accept();
  46.  
  47.         // Start the ASIO io_service run loop
  48.         echo_server.run();
  49.     } catch (websocketpp::exception const & e) {
  50.         std::cout << e.what() << std::endl;
  51.     } catch (...) {
  52.         std::cout << "other exception" << std::endl;
  53.     }
  54. }
  55.  
downloadwsPP.cpp Source code - Download uWebSockets Source code
Related Source Codes/Software:
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11

 Back to top