diff options
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; +} + |