[zeromq-dev] epgm / pgm / auto discovery in C++ on Windows and VS2013

James Chapman james at linux-101.org
Wed Nov 26 23:06:44 CET 2014

Hello ZeroMQ mailing list

I hoping someone can give me some pointers as I'm struggling with auto discovery

I'm trying to build an auto discovery mechanism whereby a server
broadcasts messages via multicast or broadcast address to which
clients will respond.

For now I'm just trying to send a message from A and receive it on B.
I should also mention that I'm trying to send and receive from the
same machine.

I've tried epgm, pgm, tcp, udp, broadcast addresses, multicast
addresses, I just don't seem to be making any headway, so any guidance
would be greatly appreciated. Where am I going wrong and has anyone
else tackled this problem on the Windows platform before?

I've copied code from the relevant sections in each module and pasted it below.

Any help would be appreciated.

Thanks in advance.


* Server sending code:
void MessageSender::sendHeartbeat()
    // Set up the connection
    zmq::context_t context(1);
    zmq::socket_t * socket = new zmq::socket_t(context, ZMQ_PUB);
    //std::string conIp = "epgm://;";
    //std::string conIp = "tcp://";
    //std::string conIp = "tcp://";
    std::string conIp("tcp://");
    int linger = 0;
    socket->setsockopt(ZMQ_LINGER, &linger, sizeof(linger));
    DEBUG_LOG("Sending Heartbeat Message");

    // Send the message
        Phoenix::Common::Message * pMessageOut = new Phoenix::Common::Message();
        pMessageOut->header.messageType = Phoenix::Common::MessageType::PING;

        zmq::message_t zmqMsgOut(sizeof(*pMessageOut) + 1);
        memcpy((void *)zmqMsgOut.data(), pMessageOut, sizeof(*pMessageOut));
        bool status = socket->send(zmqMsgOut);
        DEBUG_LOG("Heartbeat Message Sent.");

    // Close and delete the socket
    delete socket;

* Client receiving code
void HealthSlave::hearbeatResponder()
    zmq::context_t zmqContext(1);
    zmq::socket_t * pZmqSocket = new zmq::socket_t(zmqContext, ZMQ_SUB);
    //std::string listenString = "epgm://;";
    //std::string listenString = "tcp://";
    //std::string listenString = "tcp://";
    std::string listenString = "tcp://*:6669";
    DEBUG_LOG("Heartbeat responder BOUND");
    while (1)

        zmq::message_t * pZmqMsgIn = new zmq::message_t();

        catch (std::exception& e)
            std::stringstream streamErrMsg;
            streamErrMsg << "Exception caught during socket.recv(): "
<< e.what() << std::endl;

        Phoenix::Common::Message * pRpcMessageIn =
static_cast<Phoenix::Common::Message *>(pZmqMsgIn->data());
        //HealthSlave::messageHandler(pZmqSocket, pRpcMessageIn);

        INFO_OUT("============= HEARTBEAT RECEIVED ==============");

        delete pZmqMsgIn;

    delete pZmqSocket;

More information about the zeromq-dev mailing list