mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 02:56:16 +02:00
ping
git-svn-id: svn://elaine/murooma/trunk@127 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
parent
32acdc83f2
commit
d94f6c99da
2 changed files with 27 additions and 16 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue