git-svn-id: svn://elaine/murooma/trunk@127 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-07-31 20:16:07 +00:00
parent 32acdc83f2
commit d94f6c99da
2 changed files with 27 additions and 16 deletions

View file

@ -19,31 +19,42 @@ using namespace std;
void control()
void alive(zmq::socket_t* worker)
{
zmq::context_t context(1);
zmq::socket_t worker (context, ZMQ_REQ);
srand (time(NULL));
// We use a string identity for ease here
string macAddress = getMacAddress();
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
worker.connect("tcp://127.0.0.1:123459");
// Tell the router we're ready for work
s_send (worker, "ready");
while (1) {
std::string cmd = s_recv (worker);
s_send (*worker, "ping");
sleep(1);
}
}
void control(zmq::socket_t* worker)
{
// Tell the router we're ready for work
// s_send (*worker, "ready");
while (1) {
std::string cmd = s_recv (*worker);
vector<std::string> splitCmd = split(cmd);
for (size_t n=0; n<splitCmd.size(); ++n)
std::cout << "cmd: " << splitCmd[n] << "\n";
s_send(worker, "ACK " + cmd);
s_send(*worker, "ACK " + cmd);
}
}
int main () {
cout << getMacAddress() << "\n";
std::thread controlThread(control);
zmq::context_t context(1);
zmq::socket_t worker (context, ZMQ_DEALER);
srand (time(NULL));
// We use a string identity for ease here
string macAddress = getMacAddress();
worker.setsockopt(ZMQ_IDENTITY, macAddress.c_str(), macAddress.length());
worker.connect("tcp://127.0.0.1:123459");
std::thread controlThread(control, &worker);
std::thread aliveThread(alive, &worker);
controlThread.join();
return 0;
}