From 717bead50c8b209dac3f6ac8cb2c081613850d26 Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Wed, 4 Mar 2015 17:50:46 +0100 Subject: nanomsg examples --- nanomsg/pipeline.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 nanomsg/pipeline.cc (limited to 'nanomsg/pipeline.cc') diff --git a/nanomsg/pipeline.cc b/nanomsg/pipeline.cc new file mode 100644 index 0000000..704f24c --- /dev/null +++ b/nanomsg/pipeline.cc @@ -0,0 +1,54 @@ +/* + * template.cpp + * + * Patrick Simianer + * YYYY-MM-DD + */ + +#include +#include +#include +#include +#include + +using namespace std; + +void +receiver(const string url) +{ + nn::socket s(AF_SP, NN_PULL); + s.bind(url.c_str()); + while (1) { + char *buf = NULL; + s.recv(&buf, NN_MSG, 0); + cout << "receiving " << buf << endl; + } +} + +void +send(const string url, const string msg) +{ + + nn::socket s(AF_SP, NN_PUSH); + s.connect(url.c_str()); + cout << "sending " << msg << endl; + s.send(msg.c_str(), msg.size()+1, 0); +} + +int main(int argc, char const* argv[]) +{ + string cmd(argv[1]); + if (cmd == "send") { + ostringstream msg; + string url(argv[2]); + for (size_t i = 3; i < argc; i++) + msg << argv[i]; + send(url, msg.str()); + } else { + string url(argv[1]); + receiver(url); + } + + return 0; +} + -- cgit v1.2.3