diff options
author | Patrick Simianer <p@simianer.de> | 2015-03-04 17:50:46 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-03-04 17:50:46 +0100 |
commit | 717bead50c8b209dac3f6ac8cb2c081613850d26 (patch) | |
tree | 286b7a073670df59c55d2f9745678ac4c179c513 /nanomsg/pipeline.cc | |
parent | c0ece722bd7775af14c7f2ec18dcd1fd138607cb (diff) |
nanomsg examples
Diffstat (limited to 'nanomsg/pipeline.cc')
-rw-r--r-- | nanomsg/pipeline.cc | 54 |
1 files changed, 54 insertions, 0 deletions
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 <p@simianer.de> + * YYYY-MM-DD + */ + +#include <iostream> +#include <nanomsg/nn.h> +#include <nanomsg/pipeline.h> +#include <nn.hpp> +#include <sstream> + +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; +} + |