Re: [zeromq-dev] How to work with poll on socket ZMQ_SUB

2018-03-22 Thread Bernardo Augusto García Loaiza
I did code my client application of this way:

#include 
#include 
#include 
#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);

while (1)
{
// Wait for next request from client
std::string string = s_recv(subscriber);

std::cout << "Received request: " << string << std::endl;

// Do some 'work'
sleep(1);

// Send reply back to client
// s_send(responder, "Hola soy un responder 1");
}
}






Bernardo Augusto García Loaiza
Ingeniero de Sistemas
Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT
http://about.me/bgarcial


On Thu, Mar 22, 2018 at 12:26 PM, Bernardo Augusto García Loaiza <
botib...@gmail.com> wrote:

> 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 
> #include 
> #include 
> #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(, 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


[zeromq-dev] How to work with poll on socket ZMQ_SUB

2018-03-22 Thread Bernardo Augusto García Loaiza
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 
#include 
#include 
#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(, 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