/* * 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; }