[zeromq-dev] ZeroMQ and UDP

2018-06-08 Thread Bernardo Augusto García Loaiza
Hi ZMQ people.
Why UDP is only supported on ZMQ_RADIO and ZMQ_DISH sockets?

Are these sockets even used currently?

Best Regards

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


Re: [zeromq-dev] PUB-PULL Messaging Broker Improve the messaging

2018-03-23 Thread Bernardo Augusto García Loaiza
 workflow, I think that before to I ask others to deductively answer why
something happens at your desk application  distributed behavior, I
should perform some experiments about of performance and networking
conditions and workload on each peer and the transport protocols used

Any consideration about of how to start with these experiments.

How to can I measure the arrival time of messages on each peer when these
messages departure from their source or origin peer?

Thanks.




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 5:23 PM, Bernardo Augusto García Loaiza <
botib...@gmail.com> wrote:

> I have implemented this ZMQ Client-Server architecture with the order to
> one message from *Sender* client, this message arrives at other clients 
> *Receiver
> 1, Receiver 2 and Receiver 3.*
>
> This means that the all receivers can see the same data from *Sender*
>
>
> In this architecture, I have python clients and c++ clients. The server is
> coded with Python using pyzmq binding.
>
> The question is: Why on my python clients the message appears faster than
> on my c++ clients?
>
> This is related to the server is coded in Python?
>
> What kind of nonfunctionals considerations should I have to improve the
> performance of the messaging system?
>
> Is possible think in one thread by each message routed to the receiver?
>
> I would meet your considerations about it
>
>
> 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] PUB-PULL Messaging Broker Improve the messaging

2018-03-22 Thread Bernardo Augusto García Loaiza
I have implemented this ZMQ Client-Server architecture with the order to
one message from *Sender* client, this message arrives at other
clients *Receiver
1, Receiver 2 and Receiver 3.*

This means that the all receivers can see the same data from *Sender*


In this architecture, I have python clients and c++ clients. The server is
coded with Python using pyzmq binding.

The question is: Why on my python clients the message appears faster than
on my c++ clients?

This is related to the server is coded in Python?

What kind of nonfunctionals considerations should I have to improve the
performance of the messaging system?

Is possible think in one thread by each message routed to the receiver?

I would meet your considerations about it


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


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


[zeromq-dev] ZMQ_DEALER have some identity by default

2018-03-15 Thread Bernardo Augusto García Loaiza
Hi ZMQ people.

The different sockets types , by default zmq assign the identity value ?

How to know I the IDENTITY of a socket created ?

Best Regards

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


Re: [zeromq-dev] ZMQ DEALER - ROUTER Communication

2018-03-15 Thread Bernardo Augusto García Loaiza
Hi Stephen.

I unknown if the previous message was sent to group list due to arrive
moderation notification about of the long of same. By this reason I sent
this message now.


In first instance, thanks for your answering

I am set  the identity of each peer/client in their respective ZMQ_DEALER
client-side  with

*client.setsockopt(ZMQ_IDENTITY, "PEER1", 5);*

Is this right? The identity frame is set on the DEALER client/peer side.

When this ZMQ_DEALER client sends a message to ZMQ_ROUTER on the server
router in command line interface I can see:

[b'PEER1', b'', b'Testing sending some data']

This means, that the ROUTER socket, when receiving the message prepend the
identity message part of the originating peer to the message before passing
it to the application. It's right.

And you have the reason, the message sent by the DEALER to ROUTER is
returned to him.

The same behavior happens on the peer2 or another DEALER client

If I am attaching the identity of each DEALER before to connect to ROUTER
... how to can I figure the identity frame of other DEALER destination of
this message?
This should be making on the ROUTER side?

In the first instance, to starting in my implementation, I need that some
message sent by any DEALER, this will be visualized by any another DEALER
without matter how many DEALERS (one or many) are connected to the
ZMQ_ROUTER.

In this sense ... Is necessary meet about of the identity frame of other
DEALER or other DEALERS?

If I have DEALER A, DEALER B, and DEALER C, and ROUTER

then:

DEALER A send a message ...
And  I want that message from DEALER A to arrive at DEALER B and DEALER C
and so other DEALERS that can be joined to my session conversation ...

In this ideas order, is necessary met the identity frame of DEALER B and
DEALER C previously so that this message to arrive him?

How to know the identity frames of each DEALER existent on my
implementation?
This is made on the ROUTER side?
I haven't clear this.

Best Regards




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 15, 2018 at 6:59 AM, Stephen Gray <riskybizl...@live.com> wrote:

> Hi Bernardo,
>
>
>
> The http://zguide.zeromq.org/page:all tells us;
>
>
>
> “The ROUTER socket, unlike other sockets, tracks every connection it has,
> and tells the caller about these. The way it tells the caller is to stick
> the connection *identity* in front of each message received. An identity,
> sometimes called an *address*, is just a binary string with no meaning
> except "this is a unique handle to the connection". Then, when you send a
> message via a ROUTER socket, you first send an identity frame.
>
> The zmq_socket() <http://api.zeromq.org/3-2:zmq_socket> man page
> describes it thus:
>
> When receiving messages a ZMQ_ROUTER socket shall prepend a message part
> containing the identity of the originating peer to the message before
> passing it to the application. Messages received are fair-queued from among
> all connected peers. When sending messages a ZMQ_ROUTER socket shall remove
> the first part of the message and use it to determine the identity of the
> peer the message shall be routed to.”
>
> Though I haven’t run your code I suspect that your ROUTER will bounce back
> your test message to the originating DEALER?  This would be because the
> identity frame was prepended by the ROUTER on receipt and the message is
> sent back through the ROUTER; where it strips off the identity and uses the
> value to route the message back to the relevant DEALER.
>
> In order to send it to a different destination it is necessary to have the
> ‘identity’ frame of that other DEALER and to prepend that identity when you
> send the message; otherwise the ROUTER won’t know where to deliver the
> message.
>
> When receiving off a ROUTER socket the ‘identity’ is the first frame of
> the message.  You could capture it and store it. Then later prepend it as
> the first frame of a message you wish to send to a particular DEALER via
> your ROUTER.
>
> HTH,
>
> Stephen
>
>
>
>
>
> *From:* zeromq-dev [mailto:zeromq-dev-boun...@lists.zeromq.org] *On
> Behalf Of *Bernardo Augusto García Loaiza
> *Sent:* 14 March 2018 23:17
> *To:* ZeroMQ development list
> *Subject:* [zeromq-dev] ZMQ DEALER - ROUTER Communication
>
>
>
> I am currently working on a project that requires some communication over
> the network of a different data types from some entities of a distributed
> system and I am using ZMQ.
>
> The main goal of the project is to have a central node which services
> clients which can connect at any time. For each client connected, the
> central node should manage the message communication betwe

Re: [zeromq-dev] ZMQ DEALER - ROUTER Communication

2018-03-15 Thread Bernardo Augusto García Loaiza
Hi Stephen.

Thanks for your answering

I am set  the identity of each peer/client in their respective ZMQ_DEALER
client-side  with

client.setsockopt(ZMQ_IDENTITY, "PEER1", 5);


When this ZMQ_DEALER client send a message to ZMQ_ROUTER



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 15, 2018 at 6:59 AM, Stephen Gray <riskybizl...@live.com> wrote:

> Hi Bernardo,
>
>
>
> The http://zguide.zeromq.org/page:all tells us;
>
>
>
> “The ROUTER socket, unlike other sockets, tracks every connection it has,
> and tells the caller about these. The way it tells the caller is to stick
> the connection *identity* in front of each message received. An identity,
> sometimes called an *address*, is just a binary string with no meaning
> except "this is a unique handle to the connection". Then, when you send a
> message via a ROUTER socket, you first send an identity frame.
>
> The zmq_socket() <http://api.zeromq.org/3-2:zmq_socket> man page
> describes it thus:
>
> When receiving messages a ZMQ_ROUTER socket shall prepend a message part
> containing the identity of the originating peer to the message before
> passing it to the application. Messages received are fair-queued from among
> all connected peers. When sending messages a ZMQ_ROUTER socket shall remove
> the first part of the message and use it to determine the identity of the
> peer the message shall be routed to.”
>
> Though I haven’t run your code I suspect that your ROUTER will bounce back
> your test message to the originating DEALER?  This would be because the
> identity frame was prepended by the ROUTER on receipt and the message is
> sent back through the ROUTER; where it strips off the identity and uses the
> value to route the message back to the relevant DEALER.
>
> In order to send it to a different destination it is necessary to have the
> ‘identity’ frame of that other DEALER and to prepend that identity when you
> send the message; otherwise the ROUTER won’t know where to deliver the
> message.
>
> When receiving off a ROUTER socket the ‘identity’ is the first frame of
> the message.  You could capture it and store it. Then later prepend it as
> the first frame of a message you wish to send to a particular DEALER via
> your ROUTER.
>
> HTH,
>
> Stephen
>
>
>
>
>
> *From:* zeromq-dev [mailto:zeromq-dev-boun...@lists.zeromq.org] *On
> Behalf Of *Bernardo Augusto García Loaiza
> *Sent:* 14 March 2018 23:17
> *To:* ZeroMQ development list
> *Subject:* [zeromq-dev] ZMQ DEALER - ROUTER Communication
>
>
>
> I am currently working on a project that requires some communication over
> the network of a different data types from some entities of a distributed
> system and I am using ZMQ.
>
> The main goal of the project is to have a central node which services
> clients which can connect at any time. For each client connected, the
> central node should manage the message communication between the two.
>
> Currently, and by the moment, all communication is happening over TCP.
>
> The clients need to send and receive messages at any time so they are
> *ZMQ_DEALER* type sockets and the central node is *ZMQ_ROUTER*
>
> I have been reading, about of the different patterns communication and I
> think the Asynchronous Client/Server pattern
> <http://zguide.zeromq.org/page:all#The-Asynchronous-Client-Server-Pattern>
> is suited because I am interested in having several clients talking to each
> other in a collaborative way, having maybe a server broker or middleware,
> which be useful to receive and forward messages between entities related
> and because basically, the DEALER - TO - ROUTER
> <http://zguide.zeromq.org/php:chapter3#The-DEALER-to-ROUTER-Combination>
> combination is that I need.
>
>
>
> I have a ZMQ_DEALER socket client which connect to ZMQ_ROUTER socket
> server
>
> #include 
>
> #include "zhelpers.hpp"
>
> using namespace std;
>
>
>
> int main(int argc, char *argv[])
>
> {
>
>
>
> zmq::context_t context(1);
>
> zmq::socket_t client(context, ZMQ_DEALER);
>
>
>
> const string endpoint = "tcp://localhost:5559";
>
>
>
> client.setsockopt(ZMQ_IDENTITY, "PEER1", 5);
>
> cout << "Connecting to ZMQ Network Manager " << endpoint << "..." << endl;
>
> client.connect(endpoint);
>
> for (int request = 0; request < 10; request++)
>
> {
>
>
>
> s_sendmore(client, "");
>
> s_send(client, &quo

[zeromq-dev] ZMQ DEALER - ROUTER Communication

2018-03-14 Thread Bernardo Augusto García Loaiza
I am currently working on a project that requires some communication over
the network of a different data types from some entities of a distributed
system and I am using ZMQ.

The main goal of the project is to have a central node which services
clients which can connect at any time. For each client connected, the
central node should manage the message communication between the two.
Currently, and by the moment, all communication is happening over TCP.

The clients need to send and receive messages at any time so they are
*ZMQ_DEALER* type sockets and the central node is *ZMQ_ROUTER*

I have been reading, about of the different patterns communication and I
think the Asynchronous Client/Server pattern
<http://zguide.zeromq.org/page:all#The-Asynchronous-Client-Server-Pattern>
is suited because I am interested in having several clients talking to each
other in a collaborative way, having maybe a server broker or middleware,
which be useful to receive and forward messages between entities related
and because basically, the DEALER - TO - ROUTER
<http://zguide.zeromq.org/php:chapter3#The-DEALER-to-ROUTER-Combination>
combination is that I need.



I have a ZMQ_DEALER socket client which connect to ZMQ_ROUTER socket server

#include #include "zhelpers.hpp"using namespace std;
int main(int argc, char *argv[]){

zmq::context_t context(1);
zmq::socket_t client(context, ZMQ_DEALER);

const string endpoint = "tcp://localhost:5559";

client.setsockopt(ZMQ_IDENTITY, "PEER1", 5);
cout << "Connecting to ZMQ Network Manager " << endpoint << "..." << endl;
client.connect(endpoint);
for (int request = 0; request < 10; request++)
{

s_sendmore(client, "");
s_send(client, "Testing sending some data");

std::string string = s_recv(client);

std::cout << "Received reply " << request
  << " [" << string << "]" << std::endl;
}}


On my server code, I have a ZMQ_ROUTER which receive and manage the
messages is, making bind it to a well port. This server is made in Python

import zmq
context = zmq.Context()
frontend = context.socket(zmq.ROUTER)
frontend.bind("tcp://*:5559")
# Initialize a poll set
poller = zmq.Poller()
poller.register(frontend, zmq.POLLIN)
print("Creating Server Network Manager Router")
while True:
socks = dict(poller.poll())

if socks.get(frontend) == zmq.POLLIN:
message = frontend.recv_multipart()
print(message)
frontend.send_multipart(message)


On my other peer/client I have the following:


#include #include "zhelpers.hpp"using namespace std;
int main (int argc, char *argv[]){

zmq::context_t context(1);
zmq::socket_t peer2(context, ZMQ_DEALER);

const string endpoint = "tcp://localhost:5559";

peer2.setsockopt(ZMQ_IDENTITY, "PEER2", 5);
cout << "Connecting to ZMQ Network Manager " << endpoint << "..." << endl;
peer2.connect(endpoint);
//s_sendmore(peer2, "");
//s_send(peer2, "Probando");

//std::string string = s_recv(peer2);

//std::cout << "Received reply " << " [" << string << "]" << std::endl;

for (int request = 0; request < 10; request++)
{

s_sendmore(peer2, "");
s_send(peer2, "Probando");

std::string string = s_recv(peer2);

std::cout << "Received reply " << request
          << " [" << string << "]" << std::endl;
}
}


But each that I execute some client, their respective messages do not
arrive at another peer client. The messages arrive at ZMQ_ROUTER, but I
haven't clear on my server code how to should I forward this messages to
the respective clients.

I think so (may be obvious) that in my server code, I am not sending
messages.



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] About of test The Asynchronous Client/Server Pattern

2018-02-22 Thread Bernardo Augusto García Loaiza
Hi ZMQ people

I am understanding the different socket and patterns types due to I am
interested in have several clients which talk between them of a
collaborative way, having may be a server broker or middleware .which be
useful to receive and forward messages beetween entities related.

My study/situation case is the following:
I've want denote the workflow via step numbers interaction in my diagram. I
hope not to be inconvenient with my diagram, I only refer it to better
illustrate my situation

[image: Inline image 1]


What do would be an appropriate pattern to achieve bidirectional,
asynchronous messages between two client nodes which exchange messages
?


Due to this previously mentioned ... I have been reading and the ZMQ_ROUTER
and ZMQ_DEALER sockets they seem to be a good option due to the ongoing and
incoming routing strategy.

I understand that the process of queuing each received message from all
peers connected (in ZMQ_DEALER)
and and *each message sent is round-robined *among all connected peers

What mean round-robined?

With the ZMQ_ROUTER happen somethng similar in relation to incoming routing
strategy ...

I have been test the Shared Queue Dealer and Router sockets
<http://zguide.zeromq.org/page:all#Shared-Queue-DEALER-and-ROUTER-sockets>
samples
but the process is synchronous, due to  I've used it in a
REQ-ROUTER-DEALER-REP set up but in that case the REQ -> ROUTER send does
not target a particular handler on the other side, it just goes to an
arbitrary one and the ROUTER makes sure the reply goes back to the original
sender.

I think that my situation is similar to this Jake's question
<https://lists.zeromq.org/pipermail/zeromq-dev/2018-February/032284.html>


The broker approach ROUTER-DEALER ... is right think about it?
Or the communication may be client to client directly?

I write to this mail list with the order to share my considerations and
learn and receive some orientation of you ZMQ people in relation to
the appropriate
pattern to achieve bidirectional, asynchronous messages between two client
nodes.

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 get data a ZMQ_PUB service?

2018-02-12 Thread Bernardo Augusto García Loaiza
Can I publisher service receive data from an external source and send them
to the subscribers?

In the wuserver.cpp <http://zguide.zeromq.org/cpp:wuserver> sample the data
are generated from the same script ...

Can I write a ZMQ_PUBLISHER entity which receive data from external data
source / application ... ?

[image: Inline image 1]
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] Considering ZMQ patterns to many clients - server implementation

2018-02-09 Thread Bernardo Augusto García Loaiza
There is the REQ-REP an d PUB-SUB patterns between others...

[image: fig2.png]
  [image: fig4.png]

How to ZMQ_PUB get the data that send to subscribers?
The ZMQ_PUB process is connected or communicate with some data source ? ...
I guess..

I think that I will should test ... sure ! but ...
A client  ZMQ_REQ socket  such as follow  ...
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);

This REQ socket, can send data to ZMQ_PUB socket server?
zmq::context_t context (1);
zmq::socket_t publisher (context, ZMQ_PUB);

I have some client external entity named Client 1 which send some data via
zmq
with the order that data be sent to another peers external entity Client 2,
... , Client 3 , Client n ...

The idea, is that external clients are sending data of a constant way , due
to all it is a collaborative system
in which one client action is received and  visualized on the other
clients, reason by which each client in some point
will be in a process of receive or get events and show in their local
respective workspaces.

That's all it's something like a collaborative environment, similar to
multiplayer game.

According to previous, is right think in a Middleware ZMQ server of
ZMQ_PUB  type
which receive the events of the each external client (this connection is
performed via ZMQ_REQ in case of be possible)
and at the same time each external client are subscribed to this Middleware
ZMQ_PUB server receiving events ...

Is this possible according to ZMQ Architecture and Patterns? or I am wrong?

I need think in that is necessary one middleware/intermediate, which allows
multiple connections to arrive and in each connection multiple messages via
socket.send

Initially, I have in this moment a REQ-REP ZMQ implementation in which from
a C++ client I send some
data from external client to Python server ZMQ_REP.  The idea is that the
Python Server act like that middleware
and receive:

   - Multiple data from each external C++ client
   - Due to the collaborative nature system, also the connection of more
   than one external c++ client is necessary when two or more users interact
   between them

In this situation I will have n clients sending n requests on a single port

By this reasons the Python server ZMQ_REP should support multiple
connections and messages with the order to be delivery to another c++
clients an I think that the a ZMQ_REP socket server is not suited to this
tasks ... I am right with these affirmation?
I think this, because I am sending data form clients in two moments or
times, and the ZMQ_REP socket only accept the first
socket.send(request)  from a ZMQ_REQ connection and the other is ignored or
my program crash ..

In this answer about of topic

talk
about of similar situation and reference the *ZMQ_ROUTER* sockets figure
and the client server interaction is perform via PUB-SUB pattern.

This response has motivated me to share my situation with you zmq people
group
in order to obtain some guidance regarding your experience with zeromq.org

My apologies if my case is too long in this message, I did want give wide
detail about it and my proposal about of how to
address.

Thanks for your orientation
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev


[zeromq-dev] Using zmqpp client tool

2018-02-05 Thread Bernardo Augusto García Loaiza
Recently I've build the zmqpp c++ binding

In your installation process is created a zmqpp client tool CLI to test of
a basic way some sockets communications. ..

https://github.com/zeromq/zmqpp/#usage


How to can I usage the flags to execute the client?

I try this

→ ./zmqpp --connect req tcp://localhost:
  [818f9c3]
Unknown value 'tcp://localhost:' provided for 0mq socket type.
Usage: zmqpp [options] SOCKETTYPE ENDPOINT
0mq command line client tool.
SOCKETTYPE is one of the supported 0mq socket types.
  pull, push, pub, sub, req, rep
ENDPOINT is any valid 0mq endpoint.


But  the connection options is not clear for me ...

I have a socket server in the  port/

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


Re: [zeromq-dev] Building C++ binding zmq - zmqpp step

2018-02-05 Thread Bernardo Augusto García Loaiza
Thanks Thomas.

I've install the  libboost-test-dev with apt-get in my machine and all it's
works
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev


[zeromq-dev] Building C++ binding zmq - zmqpp step

2018-02-02 Thread Bernardo Augusto García Loaiza
Hi ZMQ people.

I am building the c++ binding zmq and I have this inconvenient which I've
entered as a issue <https://github.com/zeromq/zmqpp/issues/209> in the
zmqpp repository  <https://github.com/zeromq/>

In the building process,  I have the problem

++  -o ./build/max-g++/zmqpp-tests
./build/max-g++/obj/tests/test_inet.o
./build/max-g++/obj/tests/test_z85.o
./build/max-g++/obj/tests/test_context.o
./build/max-g++/obj/tests/test_message.o
./build/max-g++/obj/tests/test_auth.o
./build/max-g++/obj/tests/test_actor.o
./build/max-g++/obj/tests/test_load.o
./build/max-g++/obj/tests/test_proxy.o
./build/max-g++/obj/tests/test_loop.o
./build/max-g++/obj/tests/test_socket_options.o
./build/max-g++/obj/tests/test_socket.o
./build/max-g++/obj/tests/test_reactor.o
./build/max-**g++/obj/tests/test_sanity.o
./build/max-g++/obj/tests/test_message_stream.o
./build/max-g++/obj/tests/test_poller.o -L./build/max-g++ -lzmqpp
-lboost_unit_test_framework -lpthread -lzmq
/usr/bin/ld: cannot find -lboost_unit_test_framework
collect2: error: ld returned 1 exit status
Makefile:195: recipe for target 'zmqpp-tests' failed**
make: *** [zmqpp-tests] Error 1

How to can I add or install or setup the -lboost_unit_test_framework library
? ... just in case that I am in right in my appreciation problem ...


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


Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-30 Thread Bernardo Augusto García Loaiza
Hi, I again.

I've performed some small test in relation to the way on how to I sending
the data member structure.

I am turning the int data member structure to string before to be send it ..
In the following code section  I am turn btnState in string data and assign
it to string s variable and I contatenated it some additional string
content and
I sending this string concatenated result:

void ZMQComponent::instrumentDataSend(instrumentData a){
/*  Initialize the data members structure instrumentData */
a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
a.btnState = 5671;
a.openInst = 1.0f;
a.blnDataReady = false;

   * string s, test, result, d;
s = to_string(a.btnState);
test = " is a number";
result = s + test;*

/*  We send  the btnState data  */
zmq::message_t request(30);


/*  We ask for the memory address to ge the btnState content and send it. */
memcpy(request.data(), **, 30);
socket.send(request);}


The output or the message which arrive to python zmq server is the content
of
result variable (btnState turn to string in s content variable + string test
 concatenated)
and some symbols characters of the :

(cnvss_test) ➜  Python git:(ZMQCommunication) ✗ python server.py
ZMQ Server listening ...*Received message from Sofa:
b'\xb0\x1d\x19\xf4\xfd\x7f\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x0045
is a number'*

If I assign a value less than 30 in the request, by example zmq::message_t
request(10) the output in my server is:

Received message from Sofa: b'\x90\x94\xa1\x00\xfc\x7f\x00\x00\x0e\x00'

If I assign a value greater than 10 in the request, by example zmq::message_t
request(20) the output in my server is:

Received message from Sofa:
b'\x80$(\xc7\xfc\x7f\x00\x00\x0e\x00\x00\x00\x00\x00\x00\x00*45 i*

Then, the string or object which I receive in the server side, it has as
long as the length or size assigned to zmq::message_t request variable


Based in the above mentioned, is ZMQ whom add this strings in my message
received?

According to the previous process, my message is arrived to my server,

then 


 is correct attempt what the serialization process with some entity like
protocol buffer is necessary?


 I understand that use something like google protocol buffer allow have
some correlation more controlled in relation to objects sent and the
objects received in relation of their real content ...

In any case, how to can I remove the strings or characters symbols that are
added in the message arrived to the server?








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


On Sat, Jan 27, 2018 at 11:24 AM, Thomas Rodgers <rodg...@twrodgers.com>
wrote:

> “strat team” was supposed to be std::stringstream (Thanks for nothing
> autocorrect!)
>
> http://en.cppreference.com/w/cpp/io/basic_stringstream
>
> On Sat, Jan 27, 2018 at 10:22 AM Thomas Rodgers <rodg...@twrodgers.com>
> wrote:
>
>> Strings are the simplest. If you don’t need to parse the data on the C++
>> side, just format it as a JSON map on the C++ side, stream it into a strat
>> team, send the resulting string on the socket and use Python’s support for
>> parsing JSON on the received strong. For instance.
>>
>> You can also send structured binary to Python, as I mentioned; the Python
>> CTypes module (included with Python) will let you define accessors for that
>> data. As long as the sending and receiving side are the same CPU
>> architecture you don’t have to worry about endianess conversions.
>>
>> On Sat, Jan 27, 2018 at 9:13 AM Bernardo Augusto García Loaiza <
>> botib...@gmail.com> wrote:
>>
>>> Hi Luca, this mean, then, with structured string or data is necessary
>>> some middleware entity like GPB such as Thomas tell us ...
>>>
>>>
>>> Bernardo Augusto García Loaiza
>>> Ingeniero de Sistemas
>>> Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT
>>> http://about.me/bgarcial
>>>
>>>
>>> On Sat, Jan 27, 2018 at 10:07 AM, Luca Boccassi <luca.bocca...@gmail.com
>>> > wrote:
>>>
>>>> Yes you can just send unstructured binary data or strings - Python has
>>>> native helpers for strings, and CZMQ as well
>>>>
>>>> On Fri, 2018-01-26 at 21:27 -0500, Bernardo Augusto García Loaiza
>>>> wrote:
>>>> > Thomas, I understand perfectly your explanation. But I want share
>>>> > with you
>>>> > another similar case, just for curiosity or to receive some
>>>> > additional
>>>> > orientation about it.
>>>> >
>>>> >

Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-27 Thread Bernardo Augusto García Loaiza
Hi Luca, this mean, then, with structured string or data is necessary some
middleware entity like GPB such as Thomas tell us ...


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


On Sat, Jan 27, 2018 at 10:07 AM, Luca Boccassi <luca.bocca...@gmail.com>
wrote:

> Yes you can just send unstructured binary data or strings - Python has
> native helpers for strings, and CZMQ as well
>
> On Fri, 2018-01-26 at 21:27 -0500, Bernardo Augusto García Loaiza
> wrote:
> > Thomas, I understand perfectly your explanation. But I want share
> > with you
> > another similar case, just for curiosity or to receive some
> > additional
> > orientation about it.
> >
> > I have a script client C++ ZEROMQ  as a documentation, and I have
> > script
> > server python, together based in the documentation zeromq website.
> > This mean, together are scripts basics
> >
> > From C++ client I am sending the string message
> > <https://github.com/bgarcial/zeroMQ_Client/blob/master/client.cpp#L27
> > >  and
> > I have a python server which receive this string message client
> > <https://github.com/bgarcial/zeroMQ_Client/blob/master/Python/server.
> > py#L20>
> > of  a direct way and show me their content
> >
> > In this basic sample (documentation zmq based) I am not
> > using  structures
> > data  members. Is for this reason that in this case I receive and I
> > can see
> > the content of the client message in the zmq server side without have
> > use
> > something like Google Protocol Buffer, This mean, is because in this
> > case I
> > am not sending any structures data  members?
> >
> > I appreciate one more your orientation
> >
> >
> > Bernardo Augusto García Loaiza
> > Ingeniero de Sistemas
> > Estudiante de Maestría en Ingeniería Informática - Universidad EAFIT
> > http://about.me/bgarcial
> >
> >
> > On Fri, Jan 26, 2018 at 7:44 AM, Thomas Rodgers <rodg...@twrodgers.co
> > m>
> > wrote:
> >
> > > Short answer yes, it’s related to different languages. TCP and
> > > ZeroMQ only
> > > deal with transport and framing of messages (respectively) Python
> > > has no
> > > idea that that 10 bytes corresponds to a C/C++ struct of a given
> > > layout
> > > until you tell it. Different platforms (CPU architectures) have
> > > potentially
> > > different representations of fundamental types.
> > >
> > > On Thu, Jan 25, 2018 at 4:37 PM Bernardo Augusto García Loaiza <
> > > botib...@gmail.com> wrote:
> > >
> > > > One more question. Why is necessary the serialization process? It
> > > > is
> > > > assumed that zeromq works via TCP and in the TCP protocol, the
> > > > data does
> > > > not undergo any transformation? This is related with the fact of
> > > > that I
> > > > have different platform/languages?
> > > >
> > > > On Thu, Jan 25, 2018 at 4:45 PM Bernardo Augusto García Loaiza <
> > > > botib...@gmail.com> wrote:
> > > >
> > > > > Hi Thomas,
> > > > > Thanks for your illustrative response
> > > > >
> > > > > I'll look Google Protocol Buffers. My sender is from C++
> > > > > language and
> > > > > my reception is Python. What sort of installation recommend me
> > > > > you?
> > > > > Binaries or build protocol buffer along my C++ runtime? or o
> > > > > build protoc
> > > > > binary from source?
> > > > >
> > > > > On Wed, Jan 24, 2018 at 8:36 PM Thomas Rodgers <rodgert@twrodge
> > > > > rs.com>
> > > > > wrote:
> > > > >
> > > > > > You can have a look at Python’s ctypes module, which will let
> > > > > > you
> > > > > > define a ‘struct’ from Python with the same layout as your
> > > > > > C++ struct.
> > > > > >
> > > > > > You can also investigate any number of serialization
> > > > > > libraries that
> > > > > > have C++ and Python support, eg ProtoBufs or Thrift, or
> > > > > > MagPack or whatever.
> > > > > >
> > > > > > On Wed, Jan 24, 2018 at 5:26 PM Bernardo Augusto García
> > > > > > Loaiza <
> > > > > > botib...@gmail.com&

Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-26 Thread Bernardo Augusto García Loaiza
Thomas, I understand perfectly your explanation. But I want share with you
another similar case, just for curiosity or to receive some additional
orientation about it.

I have a script client C++ ZEROMQ  as a documentation, and I have script
server python, together based in the documentation zeromq website.
This mean, together are scripts basics

>From C++ client I am sending the string message
<https://github.com/bgarcial/zeroMQ_Client/blob/master/client.cpp#L27>  and
I have a python server which receive this string message client
<https://github.com/bgarcial/zeroMQ_Client/blob/master/Python/server.py#L20>
of  a direct way and show me their content

In this basic sample (documentation zmq based) I am not using  structures
data  members. Is for this reason that in this case I receive and I can see
the content of the client message in the zmq server side without have use
something like Google Protocol Buffer, This mean, is because in this case I
am not sending any structures data  members?

I appreciate one more your orientation


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


On Fri, Jan 26, 2018 at 7:44 AM, Thomas Rodgers <rodg...@twrodgers.com>
wrote:

> Short answer yes, it’s related to different languages. TCP and ZeroMQ only
> deal with transport and framing of messages (respectively) Python has no
> idea that that 10 bytes corresponds to a C/C++ struct of a given layout
> until you tell it. Different platforms (CPU architectures) have potentially
> different representations of fundamental types.
>
> On Thu, Jan 25, 2018 at 4:37 PM Bernardo Augusto García Loaiza <
> botib...@gmail.com> wrote:
>
>> One more question. Why is necessary the serialization process? It is
>> assumed that zeromq works via TCP and in the TCP protocol, the data does
>> not undergo any transformation? This is related with the fact of that I
>> have different platform/languages?
>>
>> On Thu, Jan 25, 2018 at 4:45 PM Bernardo Augusto García Loaiza <
>> botib...@gmail.com> wrote:
>>
>>> Hi Thomas,
>>> Thanks for your illustrative response
>>>
>>> I'll look Google Protocol Buffers. My sender is from C++ language and
>>> my reception is Python. What sort of installation recommend me you?
>>> Binaries or build protocol buffer along my C++ runtime? or o build protoc
>>> binary from source?
>>>
>>> On Wed, Jan 24, 2018 at 8:36 PM Thomas Rodgers <rodg...@twrodgers.com>
>>> wrote:
>>>
>>>> You can have a look at Python’s ctypes module, which will let you
>>>> define a ‘struct’ from Python with the same layout as your C++ struct.
>>>>
>>>> You can also investigate any number of serialization libraries that
>>>> have C++ and Python support, eg ProtoBufs or Thrift, or MagPack or 
>>>> whatever.
>>>>
>>>> On Wed, Jan 24, 2018 at 5:26 PM Bernardo Augusto García Loaiza <
>>>> botib...@gmail.com> wrote:
>>>>
>>>>> Hi, ZMQ people.
>>>>> Greetings.
>>>>>
>>>>>
>>>>> I have a  C++ zeromq client process in which I am sending some data
>>>>> members structures
>>>>>
>>>>> *ZMQComponent.h* file
>>>>>
>>>>>
>>>>> #include 
>>>>> #include 
>>>>>
>>>>> // To Quat datatype
>>>>> #include 
>>>>> using sofa::defaulttype::Quat;
>>>>>
>>>>> using std::string;
>>>>>
>>>>> namespace sofa
>>>>> {
>>>>>
>>>>> namespace component
>>>>> {
>>>>>
>>>>> namespace controller
>>>>> {
>>>>>
>>>>> /* data structure which I want send data to python zmq server */
>>>>> struct instrumentData
>>>>> {
>>>>> typedef sofa::defaulttype::Vec3d Vec3d;
>>>>> Vec3d pos;
>>>>> Quat quat;
>>>>> int btnState;
>>>>> float openInst;
>>>>> bool blnDataReady;
>>>>> };
>>>>>
>>>>> class ZMQComponent : public sofa::core::behavior::BaseController
>>>>> {
>>>>> public:
>>>>> SOFA_CLASS(ZMQComponent, sofa::core::behavior::BaseController);
>>>>>
>>>>> ZMQComponent();
>>>>> virtual ~ZMQComponent();
>>>>> /* Conect to ZMQ external python Server */
>>>&g

Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-26 Thread Bernardo Augusto García Loaiza
Thanks Thomas. Best Regards :)

On Fri, Jan 26, 2018 at 7:44 AM Thomas Rodgers <rodg...@twrodgers.com>
wrote:

> Short answer yes, it’s related to different languages. TCP and ZeroMQ only
> deal with transport and framing of messages (respectively) Python has no
> idea that that 10 bytes corresponds to a C/C++ struct of a given layout
> until you tell it. Different platforms (CPU architectures) have potentially
> different representations of fundamental types.
>
> On Thu, Jan 25, 2018 at 4:37 PM Bernardo Augusto García Loaiza <
> botib...@gmail.com> wrote:
>
>> One more question. Why is necessary the serialization process? It is
>> assumed that zeromq works via TCP and in the TCP protocol, the data does
>> not undergo any transformation? This is related with the fact of that I
>> have different platform/languages?
>>
>> On Thu, Jan 25, 2018 at 4:45 PM Bernardo Augusto García Loaiza <
>> botib...@gmail.com> wrote:
>>
>>> Hi Thomas,
>>> Thanks for your illustrative response
>>>
>>> I'll look Google Protocol Buffers. My sender is from C++ language and
>>> my reception is Python. What sort of installation recommend me you?
>>> Binaries or build protocol buffer along my C++ runtime? or o build protoc
>>> binary from source?
>>>
>>> On Wed, Jan 24, 2018 at 8:36 PM Thomas Rodgers <rodg...@twrodgers.com>
>>> wrote:
>>>
>>>> You can have a look at Python’s ctypes module, which will let you
>>>> define a ‘struct’ from Python with the same layout as your C++ struct.
>>>>
>>>> You can also investigate any number of serialization libraries that
>>>> have C++ and Python support, eg ProtoBufs or Thrift, or MagPack or 
>>>> whatever.
>>>>
>>>> On Wed, Jan 24, 2018 at 5:26 PM Bernardo Augusto García Loaiza <
>>>> botib...@gmail.com> wrote:
>>>>
>>>>> Hi, ZMQ people.
>>>>> Greetings.
>>>>>
>>>>>
>>>>> I have a  C++ zeromq client process in which I am sending some data
>>>>> members structures
>>>>>
>>>>> *ZMQComponent.h* file
>>>>>
>>>>>
>>>>> #include 
>>>>> #include 
>>>>>
>>>>> // To Quat datatype
>>>>> #include 
>>>>> using sofa::defaulttype::Quat;
>>>>>
>>>>> using std::string;
>>>>>
>>>>> namespace sofa
>>>>> {
>>>>>
>>>>> namespace component
>>>>> {
>>>>>
>>>>> namespace controller
>>>>> {
>>>>>
>>>>> /* data structure which I want send data to python zmq server */
>>>>> struct instrumentData
>>>>> {
>>>>> typedef sofa::defaulttype::Vec3d Vec3d;
>>>>> Vec3d pos;
>>>>> Quat quat;
>>>>> int btnState;
>>>>> float openInst;
>>>>> bool blnDataReady;
>>>>> };
>>>>>
>>>>> class ZMQComponent : public sofa::core::behavior::BaseController
>>>>> {
>>>>> public:
>>>>> SOFA_CLASS(ZMQComponent, sofa::core::behavior::BaseController);
>>>>>
>>>>> ZMQComponent();
>>>>> virtual ~ZMQComponent();
>>>>> /* Conect to ZMQ external python Server */
>>>>> void setupConnection();
>>>>>
>>>>> /* Send some data memeber instrumentData structure to ZMQ external
>>>>> Server */
>>>>> void instrumentDataSend(instrumentData a);
>>>>>
>>>>> /* initialize function */
>>>>> void init();
>>>>>
>>>>> };
>>>>>
>>>>> } // namespace sofa
>>>>>
>>>>> } // namespace component
>>>>>
>>>>> } // namespace controller
>>>>>
>>>>>
>>>>> The *ZMQComponent.cpp* is:
>>>>>
>>>>> #include 
>>>>> #include 
>>>>> #include 
>>>>> #include 
>>>>> #include "ZMQComponent.h"
>>>>>
>>>>>
>>>>> using namespace std;
>>>>>
>>>>> namespace sofa
>>>>> {
>>>>>
>>>>> namespace component
>>>>> {
>>>>>
>>>>> namespace controll

Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-25 Thread Bernardo Augusto García Loaiza
One more question. Why is necessary the serialization process? It is
assumed that zeromq works via TCP and in the TCP protocol, the data does
not undergo any transformation? This is related with the fact of that I
have different platform/languages?

On Thu, Jan 25, 2018 at 4:45 PM Bernardo Augusto García Loaiza <
botib...@gmail.com> wrote:

> Hi Thomas,
> Thanks for your illustrative response
>
> I'll look Google Protocol Buffers. My sender is from C++ language and my
> reception is Python. What sort of installation recommend me you? Binaries
> or build protocol buffer along my C++ runtime? or o build protoc binary
> from source?
>
> On Wed, Jan 24, 2018 at 8:36 PM Thomas Rodgers <rodg...@twrodgers.com>
> wrote:
>
>> You can have a look at Python’s ctypes module, which will let you define
>> a ‘struct’ from Python with the same layout as your C++ struct.
>>
>> You can also investigate any number of serialization libraries that have
>> C++ and Python support, eg ProtoBufs or Thrift, or MagPack or whatever.
>>
>> On Wed, Jan 24, 2018 at 5:26 PM Bernardo Augusto García Loaiza <
>> botib...@gmail.com> wrote:
>>
>>> Hi, ZMQ people.
>>> Greetings.
>>>
>>>
>>> I have a  C++ zeromq client process in which I am sending some data
>>> members structures
>>>
>>> *ZMQComponent.h* file
>>>
>>>
>>> #include 
>>> #include 
>>>
>>> // To Quat datatype
>>> #include 
>>> using sofa::defaulttype::Quat;
>>>
>>> using std::string;
>>>
>>> namespace sofa
>>> {
>>>
>>> namespace component
>>> {
>>>
>>> namespace controller
>>> {
>>>
>>> /* data structure which I want send data to python zmq server */
>>> struct instrumentData
>>> {
>>> typedef sofa::defaulttype::Vec3d Vec3d;
>>> Vec3d pos;
>>> Quat quat;
>>> int btnState;
>>> float openInst;
>>> bool blnDataReady;
>>> };
>>>
>>> class ZMQComponent : public sofa::core::behavior::BaseController
>>> {
>>> public:
>>> SOFA_CLASS(ZMQComponent, sofa::core::behavior::BaseController);
>>>
>>> ZMQComponent();
>>> virtual ~ZMQComponent();
>>> /* Conect to ZMQ external python Server */
>>> void setupConnection();
>>>
>>> /* Send some data memeber instrumentData structure to ZMQ external
>>> Server */
>>> void instrumentDataSend(instrumentData a);
>>>
>>> /* initialize function */
>>> void init();
>>>
>>> };
>>>
>>> } // namespace sofa
>>>
>>> } // namespace component
>>>
>>> } // namespace controller
>>>
>>>
>>> The *ZMQComponent.cpp* is:
>>>
>>> #include 
>>> #include 
>>> #include 
>>> #include 
>>> #include "ZMQComponent.h"
>>>
>>>
>>> using namespace std;
>>>
>>> namespace sofa
>>> {
>>>
>>> namespace component
>>> {
>>>
>>> namespace controller
>>> {
>>>
>>> /* ZMQ Internal Client context and socket */
>>> zmq::context_t context(1);
>>> zmq::socket_t socket(context, ZMQ_REQ);
>>>
>>> ZMQComponent::ZMQComponent(){}
>>>
>>> void ZMQComponent::setupConnection()
>>> {
>>> cout << "Connecting to python zeroMQ server ..." << endl;
>>> socket.connect("tcp://localhost:");
>>> }
>>>
>>> void ZMQComponent::instrumentDataSend(instrumentData a)
>>> {
>>> /* Initialize the data members structure instrumentData */
>>> a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
>>> a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
>>> a.btnState = 5671;
>>> a.openInst = 1.0f;
>>> a.blnDataReady = false;
>>>
>>> /* We send the btnState data */
>>> zmq::message_t request(10);
>>> cout << "The data are: " << a.btnState;
>>>
>>> /* We ask for the memory address to ge the btnState content and send it.
>>> */
>>> memcpy(request.data(), , 10);
>>> socket.send(request);
>>> }
>>>
>>>
>>> /* In the init function we create the objects to setup connection and
>>> send data */
>>> void ZMQComponent::init()
>>> {
>>> std::cout << "ZeroMQCommunication::init

Re: [zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-25 Thread Bernardo Augusto García Loaiza
Hi Thomas,
Thanks for your illustrative response

I'll look Google Protocol Buffers. My sender is from C++ language and my
reception is Python. What sort of installation recommend me you? Binaries
or build protocol buffer along my C++ runtime? or o build protoc binary
from source?

On Wed, Jan 24, 2018 at 8:36 PM Thomas Rodgers <rodg...@twrodgers.com>
wrote:

> You can have a look at Python’s ctypes module, which will let you define a
> ‘struct’ from Python with the same layout as your C++ struct.
>
> You can also investigate any number of serialization libraries that have
> C++ and Python support, eg ProtoBufs or Thrift, or MagPack or whatever.
>
> On Wed, Jan 24, 2018 at 5:26 PM Bernardo Augusto García Loaiza <
> botib...@gmail.com> wrote:
>
>> Hi, ZMQ people.
>> Greetings.
>>
>>
>> I have a  C++ zeromq client process in which I am sending some data
>> members structures
>>
>> *ZMQComponent.h* file
>>
>>
>> #include 
>> #include 
>>
>> // To Quat datatype
>> #include 
>> using sofa::defaulttype::Quat;
>>
>> using std::string;
>>
>> namespace sofa
>> {
>>
>> namespace component
>> {
>>
>> namespace controller
>> {
>>
>> /* data structure which I want send data to python zmq server */
>> struct instrumentData
>> {
>> typedef sofa::defaulttype::Vec3d Vec3d;
>> Vec3d pos;
>> Quat quat;
>> int btnState;
>> float openInst;
>> bool blnDataReady;
>> };
>>
>> class ZMQComponent : public sofa::core::behavior::BaseController
>> {
>> public:
>> SOFA_CLASS(ZMQComponent, sofa::core::behavior::BaseController);
>>
>> ZMQComponent();
>> virtual ~ZMQComponent();
>> /* Conect to ZMQ external python Server */
>> void setupConnection();
>>
>> /* Send some data memeber instrumentData structure to ZMQ external Server
>> */
>> void instrumentDataSend(instrumentData a);
>>
>> /* initialize function */
>> void init();
>>
>> };
>>
>> } // namespace sofa
>>
>> } // namespace component
>>
>> } // namespace controller
>>
>>
>> The *ZMQComponent.cpp* is:
>>
>> #include 
>> #include 
>> #include 
>> #include 
>> #include "ZMQComponent.h"
>>
>>
>> using namespace std;
>>
>> namespace sofa
>> {
>>
>> namespace component
>> {
>>
>> namespace controller
>> {
>>
>> /* ZMQ Internal Client context and socket */
>> zmq::context_t context(1);
>> zmq::socket_t socket(context, ZMQ_REQ);
>>
>> ZMQComponent::ZMQComponent(){}
>>
>> void ZMQComponent::setupConnection()
>> {
>> cout << "Connecting to python zeroMQ server ..." << endl;
>> socket.connect("tcp://localhost:");
>> }
>>
>> void ZMQComponent::instrumentDataSend(instrumentData a)
>> {
>> /* Initialize the data members structure instrumentData */
>> a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
>> a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
>> a.btnState = 5671;
>> a.openInst = 1.0f;
>> a.blnDataReady = false;
>>
>> /* We send the btnState data */
>> zmq::message_t request(10);
>> cout << "The data are: " << a.btnState;
>>
>> /* We ask for the memory address to ge the btnState content and send it.
>> */
>> memcpy(request.data(), , 10);
>> socket.send(request);
>> }
>>
>>
>> /* In the init function we create the objects to setup connection and
>> send data */
>> void ZMQComponent::init()
>> {
>> std::cout << "ZeroMQCommunication::init()" << std::endl;
>> ZMQComponent z;
>> z.setupConnection();
>>
>> instrumentData itemp;
>> z.instrumentDataSend(itemp);
>> }
>>
>> /* Other code related  */
>> ZMQComponent::~ZMQComponent(){}
>>
>> // int ZeroMqComponentClass = sofa::core::RegisterObject("This component
>> does nothing.").add();
>> SOFA_DECL_CLASS(ZMQServerComponent)
>>
>> int ZMQServerComponentClass = sofa::core::RegisterObject("This component
>> create a Socket.").add< ZMQServerComponent >();
>> } // namespace controller
>>
>> } // namespace component
>>
>> } // namespace sofa
>>
>> Then , my python zmq server  which receive the *btnState*  int variable
>> is:
>>
>> import time
>> import zmq
>>
>> context = zmq.Context()
>&

[zeromq-dev] Communication between C++ zmq client and Python zmq Server

2018-01-24 Thread Bernardo Augusto García Loaiza
Hi, ZMQ people.
Greetings.


I have a  C++ zeromq client process in which I am sending some data members
structures

*ZMQComponent.h* file


#include 
#include 

// To Quat datatype
#include 
using sofa::defaulttype::Quat;

using std::string;

namespace sofa
{

namespace component
{

namespace controller
{

/* data structure which I want send data to python zmq server */
struct instrumentData
{
typedef sofa::defaulttype::Vec3d Vec3d;
Vec3d pos;
Quat quat;
int btnState;
float openInst;
bool blnDataReady;
};

class ZMQComponent : public sofa::core::behavior::BaseController
{
public:
SOFA_CLASS(ZMQComponent, sofa::core::behavior::BaseController);

ZMQComponent();
virtual ~ZMQComponent();
/* Conect to ZMQ external python Server */
void setupConnection();

/* Send some data memeber instrumentData structure to ZMQ external Server */
void instrumentDataSend(instrumentData a);

/* initialize function */
void init();

};

} // namespace sofa

} // namespace component

} // namespace controller


The *ZMQComponent.cpp* is:

#include 
#include 
#include 
#include 
#include "ZMQComponent.h"


using namespace std;

namespace sofa
{

namespace component
{

namespace controller
{

/* ZMQ Internal Client context and socket */
zmq::context_t context(1);
zmq::socket_t socket(context, ZMQ_REQ);

ZMQComponent::ZMQComponent(){}

void ZMQComponent::setupConnection()
{
cout << "Connecting to python zeroMQ server ..." << endl;
socket.connect("tcp://localhost:");
}

void ZMQComponent::instrumentDataSend(instrumentData a)
{
/* Initialize the data members structure instrumentData */
a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
a.btnState = 5671;
a.openInst = 1.0f;
a.blnDataReady = false;

/* We send the btnState data */
zmq::message_t request(10);
cout << "The data are: " << a.btnState;

/* We ask for the memory address to ge the btnState content and send it. */
memcpy(request.data(), , 10);
socket.send(request);
}


/* In the init function we create the objects to setup connection and send
data */
void ZMQComponent::init()
{
std::cout << "ZeroMQCommunication::init()" << std::endl;
ZMQComponent z;
z.setupConnection();

instrumentData itemp;
z.instrumentDataSend(itemp);
}

/* Other code related  */
ZMQComponent::~ZMQComponent(){}

// int ZeroMqComponentClass = sofa::core::RegisterObject("This component
does nothing.").add();
SOFA_DECL_CLASS(ZMQServerComponent)

int ZMQServerComponentClass = sofa::core::RegisterObject("This component
create a Socket.").add< ZMQServerComponent >();
} // namespace controller

} // namespace component

} // namespace sofa

Then , my python zmq server  which receive the *btnState*  int variable is:

import time
import zmq

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:")
print('ZMQ Server listening ... ')

while True:
# Wait for next request from client
message = socket.recv()
print("Received message from Sofa: {}".format(message))
# print("Received message from c++ %s" % message)

# Do some 'work'
time.sleep(1)

# Send reply back to client
# socket.send(b"Hola cliente, muy bien y tu ?")
# print('Response sent')



The output or the message which arrive to python zmq server is the symbols
characters of the btnState:

(cnvss_test) ➜  Python git:(ZMQCommunication) ✗ python server.py
ZMQ Server listening ...
*Received message from Sofa: b"\x00'\x84)\xff\x7f\x00\x00\x98&*"

Likely, As I in my python server I am representing like  a string message
arrived and I am sending from my c++ client a int btnState data,
then I try convert int to string in  the python server side:

And I replace this line

print("Received message from Sofa: {}".format(message))

by thiis line

print("Received message from c++ %s" % str(message))

But my output is:

(cnvss_test) ➜  Python git:(ZMQCommunication) ✗ python server.py
ZMQ Server listening ...
*Received message from c++ b'\x00^n&\xff\x7f\x00\x00\xd8\\'*
Traceback (most recent call last):
  File "server.py", line 19, in 
message = socket.recv()
  File "zmq/backend/cython/socket.pyx", line 693, in
zmq.backend.cython.socket.Socket.recv
  File "zmq/backend/cython/socket.pyx", line 727, in
zmq.backend.cython.socket.Socket.recv
  File "zmq/backend/cython/socket.pyx", line 150, in
zmq.backend.cython.socket._recv_copy
  File "zmq/backend/cython/socket.pyx", line 145, in
zmq.backend.cython.socket._recv_copy
  File "zmq/backend/cython/checkrc.pxd", line 25, in
zmq.backend.cython.checkrc._check_rc
zmq.error.ZMQError: Operation cannot be accomplished in current state
(cnvss_test) ➜  Python git:(ZMQCommunication) ✗

I follow getting the characters symbolss.
My question is: How to can I represent the arrived message in my python zmq
server to show their content ?
According to this behavior, can I assume that the btnState data is sent to
python server of anyway?

Any support or orientation will be highly appreciated
___
zeromq-dev mailing