Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
1  
Could you expand on your design a bit? It seems quite strange to take a http formatted request but return a response in a different format. –  Sam Miller Feb 13 '11 at 16:06
add comment

1 Answer

If you do not want to use an HTTP library, you might try netcat or other tools that send direct messages over TCP without any particular protocol.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.