Straightforward network programming in modern C++

Getting cpp-netlib

Download

You can download the latest releases of the library at:

You can find more information about the progress of the development by checking our GitHub project page at:

Support

You can ask questions, join the discussion, and report issues to the developers mailing list by joining via:

You can also file issues on the Github issue tracker at:

We are a growing community and we are happy to accept new contributions and ideas.

Boost

The cpp-netlib is being developed for eventual submission to Boost.

_images/boost.png

C++ Network Library

The cpp-netlib is a library that provides application layer protocol support using modern C++ techniques. It is light-weight, fast, portable and is intended to be as easy to configure as possible.

It is developed by people linked to the Boost community and will soon be submitted for review into Boost. A presentation about cpp-netlib was given at BoostCon 2010, for which the slides and the paper can be found on-line.

Hello, world!

The cpp-netlib allows developers to write fast, portable network applications with the minimum of fuss.

An HTTP server-client example can be written in tens of lines of code. The client is as simple as this:

using namespace boost::network;
using namespace boost::network::http;

client::request request_("http://127.0.0.1:8000/");
request_ << header("Connection", "close");
client client_;
client::response response_ = client_.get(request);
std::string body = body(response_);

And the corresponding server code is listed below:

namespace http = boost::network::http;

struct handler;
typedef http::server<handler> http_server;

struct handler {
    void operator() (http_server::request const &request,
                     http_server::response &response) {
        response = http_server::response::stock_reply(
            http_server::response::ok, "Hello, world!");
    }

    void log(http_server::string_type const &info) {
        std::cerr << "ERROR: " << info << '\n';
    }
};

int main(int arg, char * argv[]) {
    handler handler_;
    http_server server_("0.0.0.0", "8000", handler_);
    server_.run();
}

Want to learn more?

Warning

Be aware that not all features are stable. The generic message design is under review and the URI and HTTP client implementation will continue to undergo refactoring. Future versions will include support for other network protocols.