Commit dfd717ba authored by Your Name's avatar Your Name
Browse files

.

parent c08abe9b
......@@ -3,13 +3,11 @@
// Binds SUB socket to tcp://lsldert00.local:5556
// Expects "Hello" from client, replies with "World"
//
#include "zhelpers.hpp"
#include <lsl_cpp.h>
#include <memory>
#include <iostream>
#include <iomanip>
#include <azmq/socket.hpp>
#include <boost/asio.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/program_options.hpp>
#include <unistd.h>
#include <stdio.h>
......@@ -267,11 +265,18 @@ int main(int argc, const char* argv[])
}
// Prepare our context and socket
asio::io_service ios;
azmq::sub_socket socket(ios);
socket.connect("tcp://lsldert00.local:5557");
socket.set_option(azmq::socket::subscribe(""));
zmq::context_t context(1);
zmq::socket_t srep(context, ZMQ_REP);
srep.bind("tcp://*:5555");
zmq::socket_t ssub(context, ZMQ_SUB);
ssub.connect("tcp://lsldert00.local:5557");
ssub.setsockopt(ZMQ_SUBSCRIBE, "", 0);
zmq::pollitem_t items [] = {
{ static_cast<void*>(srep), 0, ZMQ_POLLIN, 0 },
{ static_cast<void*>(ssub), 0, ZMQ_POLLIN, 0 }
};
// make a new stream_info and open an outlet with it
stream_info info(
......@@ -284,23 +289,23 @@ int main(int argc, const char* argv[])
);
outlet = new stream_outlet(info);
try {
// try {
while (run)
{
std::array<char,4096> request;
request.fill(0);
// Wait for next request from client
socket.receive(asio::buffer(request));
std::string str(request.data());
zmq::message_t request;
zmq::poll (&items [0], 2, -1);
if (items [0].revents & ZMQ_POLLIN) {
srep.recv(&request);
srep.send(request);
}
if (items [1].revents & ZMQ_POLLIN) {
ssub.recv(&request);
}
std::string str((char*)request.data());
if (verbose)
cout << "Received: " << str << endl;
// // Return result
// std::string result = str;
// socket.send(asio::buffer(result));
std::istringstream s(str);
std::string cmd;
s >> cmd;
......@@ -357,13 +362,13 @@ int main(int argc, const char* argv[])
}
}
}
catch (boost::system::system_error &e)
{
error_code ec = e.code();
std::cerr << ec.value() << '\n';
std::cerr << ec.category().name() << '\n';
}
// }
// catch (boost::system::system_error &e)
// {
// error_code ec = e.code();
// std::cerr << ec.value() << '\n';
// std::cerr << ec.category().name() << '\n';
// }
printf("\nmopping up\n");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment