View on GitHub

nanomsgxx

nanomsg binding for C++11

Download this project as a .zip file Download this project as a tar.gz file

Documentation

This document exposes the different components of nanomsgxx, provides explanations and examples on how to use them in C++ programs, as well as the API reference describing each type and functions.

Chapters

  1. Design
  2. Messages
  3. Sockets
  4. Polling
  5. API Reference

Building and installing

nanomsgxx's build is driven by waf, you can get more information about what waf is and how it works here.

waf is packaged with nanomsgxx, all you should need is a python interpreter and running these commands:

./waf configure
./waf build
./waf install

The library and headers will be installed on your system and you'll be able to link your program against libnanomsgxx.

Getting started

nanomsgxx aims to provide a very thin abstraction on top of the nanomsg C API, while taking advantage of C++11's features to make the code easier to read and write.

Quick example

#include <iostream>
#include <system_error>
#include <nnxx/message.h>
#include <nnxx/pair.h>
#include <nnxx/socket.h>

int main() {
  try {
    nnxx::socket s1 { nnxx::SP, nnxx::PAIR };
    nnxx::socket s2 { nnxx::SP, nnxx::PAIR };
    const char *addr = "inproc://example";

    s1.bind(addr);
    s2.connect(addr);

    s1.send("Hello World!");

    nnxx::message msg = s2.recv();
    std::cout << msg << std::endl;
    return 0;
  }
  catch (const std::system_error &e) {
    std::cerr << e.what() << std::endl;
    return 1;
  }
}

What did we write?

You've probably recognized most of these calls if you're familiar with nanomsg's API. nanomsgxx uses the nnxx namespace, here we have...

A few highlights

Contributing

The nanomsgxx library is MIT licensed, so you can use and modify the code as you wish.
Feel free to fork the repo on github and submit patches if you fixed a bug or want to improve nanomsgxx.

Go on to first chapter »