1

I've been trying to get an asynchronous server running with ZeroMQ with C++ (using the cppzmq bindings). My files compile fine, but I get an error in runtime of type zmq::error_t: "Socket operation on non-socket".

Here's the file that's apparently giving the error. I modeled this after the asyncsrv example from "ZeroMQ: The Guide", fixing up a few errors in the example (such as trying to std::bind to a vector for some reason).

If need be, here are my class definitions for the related source file.

Copy of the code:

#include "worker.hpp"

void SkidooshBrokerTask::run() {
    frontend.bind("tcp://*:20401");
    backend.bind("inproc://backend");

    std::vector<SkidooshBrokerWorker *> workers;
    std::vector<std::thread *> worker_threads;

    for (int i=0; i<kMaxThread; ++i) {
        workers.push_back(new SkidooshBrokerWorker(ctx,ZMQ_DEALER));
        worker_threads.push_back(new std::thread(std::bind(&SkidooshBrokerWorker::work, workers[workers.size()-1])));
        worker_threads[worker_threads.size()-1]->detach();
    }

    try {
        zmq::proxy(&frontend,&backend,nullptr);
    } catch (std::exception &e) {

    }

    for (int i=0;i<kMaxThread; ++i) {
        delete workers[i];
        delete worker_threads[i];
    }
}

void SkidooshBrokerWorker::work() {
    wk_sck.connect("inproc://backend");        
    try {
        while (true) {
            zmq::message_t identity;
            zmq::message_t msg;
            zmq::message_t copied_id;
            zmq::message_t copied_msg;
            std::string rq_str;
            wk_sck.recv(&identity);
            wk_sck.recv(&msg);

            rq_str = std::string(static_cast<char *>(msg.data()),msg.size());
            copied_id.copy(&identity);
            copied_msg.copy(&msg);
        }
    } catch (std::exception &e) {}
}
AbsoluteZero2A03
  • 193
  • 1
  • 3
  • 11

1 Answers1

0

I know this is a late answer. But I have the same error when I was using zmq::poll().

You could try to change

try 
{
    zmq::proxy(&frontend,&backend,nullptr);
} catch (std::exception &e) {}

to

try 
{
    zmq::proxy((void*)(&frontend),(void*)(&backend),nullptr);
} catch (std::exception &e) {}

Reference: For more details please check this thread.

r0n9
  • 2,505
  • 1
  • 29
  • 43