blob: 704f24c6ecfbe828f8d5e1eb61d3d42b03ded849 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
|