mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-17 11:06: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;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ void receiver(zmq::socket_t* client)
|
|||
{
|
||||
std::string address = s_recv (*client);
|
||||
// receiving and discarding'empty' message
|
||||
s_recv (*client);
|
||||
// s_recv (*client);
|
||||
// receiving and discarding 'ready' message
|
||||
std::string msg = s_recv (*client);
|
||||
std::cout << "msg from " << address << ": " << msg << "\n";
|
||||
|
@ -27,7 +27,7 @@ void receiver(zmq::socket_t* client)
|
|||
void send(const std::string& address, const std::string& cmd)
|
||||
{
|
||||
s_sendmore (*client, address);
|
||||
s_sendmore (*client, "");
|
||||
// s_sendmore (*client, "");
|
||||
s_send (*client, cmd);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ int main () {
|
|||
std::getline(std::cin, address);
|
||||
std::cout << "command: ";
|
||||
std::getline(std::cin, cmd);
|
||||
std::newl;
|
||||
std::cout << std::endl;
|
||||
send(trim(address), trim(cmd));
|
||||
}
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue