HI ZeroMQ people.

I have a server which has a PUB and PUSH sockets

The client listen to the PUB socket via SUB socket and send some data via
PUSH socket of this way:

import random
import time

import zmq

def main():
ctx = zmq.Context()
subscriber = ctx.socket(zmq.SUB)
subscriber.setsockopt_string(zmq.SUBSCRIBE, '')
subscriber.connect("tcp://localhost:5557")
publisher = ctx.socket(zmq.PUSH)
publisher.connect("tcp://localhost:5558")

random.seed(time.time())
while True:
"""
Wait 100 ms for an event in the suscriber socket
Listen to PUB server socket around of 100 ms
"""
if subscriber.poll(100) & zmq.POLLIN:
message = subscriber.recv()
print("I: received message %s" %message)


if __name__ == '__main__':
main()




How to can I work with this client in C++ version? More precisely in the
section in which I ask if in the subscriber socket came something data with
poll() feature

I try the following

#include <zmq.hpp>
#include <zmq.h>
#include <iostream>
#include "zhelpers.hpp"

using namespace std;

int main(int argc, char *argv[])
{
zmq::context_t context(1);
/*
std::cout << "Sending message to NM Server…\n" << std::endl; */

zmq::socket_t subscriber(context, ZMQ_SUB);
subscriber.connect("tcp://localhost:5557");
subscriber.setsockopt(ZMQ_SUBSCRIBE, "", 0);


/* I unknown how to work with pull here */

zmq::message_t update;
string rc;
rc = subscriber.recv(&update, ZMQ_DONTWAIT);
std::cout << "Message Received " << rc << endl;
return 0;
}


based in this sample http://zguide.zeromq.org/cpp:mspoller  Here create a
poll set but I unknow the reason.

Bernardo Augusto García Loaiza
Ingeniero de Sistemas
Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT
http://about.me/bgarcial
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to