#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::buffer(INIT_MSG_STR.c_str(), INIT_MSG_STR.length()), zmq::send_flags::dontwait); zmq::message_t msg; const auto ret = sock.recv(msg, zmq::recv_flags::dontwait); if(ret) { if(msg.to_string() == ACK_MSG_STR) { connected = true; } } } while(connected) { zmq::message_t msg; const auto ret = sock.recv(msg, zmq::recv_flags::dontwait); if(ret) { qDebug() << msg.to_string().c_str(); emit httpMessage(json(msg.to_string())); } } } }