bigsnitch/networkthread.cpp
2020-08-08 13:44:16 +02:00

39 lines
1 KiB
C++

#include "networkthread.h"
NetworkThread::NetworkThread(QObject *parent) : QObject(parent)
{
}
void NetworkThread::process() {
zmq::context_t ctx(1);
zmq::socket_t sock(ctx, zmq::socket_type::pair);
try {
sock.bind("tcp://127.0.0.1:12345");
} catch (zmq::error_t err) {
qDebug() << "failed binding socket" << err.what();
emit error(err.what());
return;
};
while(true){
bool connected = false;
while(!connected) {
sock.send(zmq::str_buffer("{'type': 'init'}"), zmq::send_flags::dontwait);
zmq::message_t msg;
const auto ret = sock.recv(msg, zmq::recv_flags::dontwait);
if(ret) {
if(msg.to_string() == "{'type': 'ack'}") {
connected = true;
}
}
}
while(connected) {
const auto ret = sock.recv(msg, zmq::recv_flags::dontwait);
if(ret) {
qDebug() << msg.to_string().c_str();
}
}
}
}