summaryrefslogtreecommitdiff
path: root/decoder/local.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-03-06 18:11:21 +0100
committerPatrick Simianer <p@simianer.de>2015-03-06 18:11:21 +0100
commit1119bc9c68deb753334049a05243483ec232dc24 (patch)
tree8feb3382aae33c55309449d60fb20fd659048bc9 /decoder/local.cc
parente838ea12018c31b8ac0437c9a740c54430276952 (diff)
toy example for sending/receiving with nanomsg -- actual files
Diffstat (limited to 'decoder/local.cc')
-rw-r--r--decoder/local.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/decoder/local.cc b/decoder/local.cc
new file mode 100644
index 00000000..b03fd17e
--- /dev/null
+++ b/decoder/local.cc
@@ -0,0 +1,51 @@
+#include <iostream>
+#include <sstream>
+#include <stdio.h>
+#include <unistd.h>
+
+#include <nanomsg/nn.h>
+#include <nanomsg/pair.h>
+#include "nn.hpp"
+
+using namespace std;
+
+void
+recv(nn::socket& sock)
+{
+ char *buf = NULL;
+ sock.recv(&buf, NN_MSG, 0);
+ if (buf) {
+ string translation(buf);
+ cout << "received translation '" << translation << "'" << endl;
+ }
+}
+
+void
+send(nn::socket& sock, const string& msg)
+{
+ cout << "sending source '" << msg << "'" << endl;
+ sock.send(msg.c_str(), msg.size()+1, 0);
+}
+
+void
+loop(nn::socket& sock)
+{
+ int to = 100;
+ sock.setsockopt(NN_SOL_SOCKET, NN_RCVTIMEO, &to, sizeof(to));
+ while(1) {
+ send(sock, "das ist ein test .");
+ sleep(1);
+ recv(sock);
+ }
+}
+
+int main(int argc, char const* argv[])
+{
+ nn::socket sock(AF_SP, NN_PAIR);
+ string url = "ipc:///tmp/network_decoder.ipc";
+ sock.connect(url.c_str());
+ loop(sock);
+
+ return 0;
+}
+