I know there is boost::asio that is made for such stuff but It would be so much easier for me if there was a way to switch between use http and not use http... (I mean I have 10 services that use http and 4 that use TCP but do quite same stuff (receive http get requests and return TCP messages ) so such function would really help for me)
So lets see an example of http serrver
#include <boost/network/protocol/http/server.hpp>
#include <string>
#include <iostream>
namespace http = boost::network::http;
struct hello_world;
typedef http::server<hello_world> server;
struct hello_world
{
void operator() (server::request const &request,
server::response &response)
{
std::string ip = source(request);
response = server::response::stock_reply(
server::response::ok, std::string("Hello, ") + ip + "!");
}
};
int
main(int argc, char * argv[])
{
if (argc != 3)
{
std::cerr << "Usage: " << argv[0] << " address port" << std::endl;
return 1;
}
try
{
hello_world handler;
server server_(argv[1], argv[2], handler);
server_.run();
}
catch (std::exception &e)
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}
How to make it return messages with out http response herder?