SHARE
TWEET

Untitled

a guest Jul 17th, 2017 42 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <boost/network/protocol/http/server.hpp>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. namespace http = boost::network::http;
  6.  
  7. struct hello_world;
  8. typedef http::server<hello_world> server;
  9.  
  10. struct hello_world {
  11.     void operator() (server::request const &request,
  12.                      server::response &response) {
  13.         std::string ip = source(request);
  14.         response = server::response::stock_reply(
  15.             server::response::ok, std::string("Hello, ") + ip + "!");
  16.     }
  17. };
  18.  
  19. int
  20. main(int argc, char * argv[]) {
  21.  
  22.     if (argc != 3) {
  23.         std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
  24.         return 1;
  25.     }
  26.  
  27.     try {
  28.         hello_world handler;
  29.         server server_(argv[1], argv[2], handler);
  30.         server_.run();
  31.     }
  32.     catch (std::exception &e) {
  33.         std::cerr << e.what() << std::endl;
  34.         return 1;
  35.     }
  36.  
  37.     return 0;
  38. }
RAW Paste Data
Top