C++ client library for nanomsg.
The library uses autotools. Use the following commands to build and install libnanomsgpp:
$ git clone git://github.com/bigdatadev/libnanomsgpp.git
$ cd libnanomsgpp
$ ./autogen.sh
$ ./configure && make && make check && make install
Create a socket and bind to a port:
#include <nanomsgpp/nanomsgpp.hpp>
namespace nn = nanomsgpp;
int main() {
try {
nn::socket socket(nn::socket_domain::sp, nn::socket_type::reply);
socket.bind("tcp://127.0.0.1:1234");
} catch (nn::internal_exception &e) {
std::cerr << "Error: " << e.error() << " - " << e.reason() << "." << std::endl;
exit (EXIT_FAILURE);
}
return (EXIT_SUCCESS);
}
Send a message:
nn::message message;
message << "Hello, world!";
socket.sendmsg(message);
Receive a message:
std::unique_ptr<nn::message> recv;
socket.recvmsg(1);
// print each message part
for (auto& part : recv) {
std::cout << part.as<char>() << std::endl;
}
For more examples, refer to the following resources:
Just send me a pull request. Please take a look at the project issues and see how you can help. Here are some tips:
- please add more tests.
- please check your syntax.
Christopher Gilbert
- Web: http://cjgilbert.me
- Twitter: @bigdatadev
- Linkedin: /in/christophergilbert
See LICENSE document