That depends on your message delivery requirements. If sensors are
involved, I would expect that those requirements are somewhat relaxed,
since the sensors generate continuous stream of data, but you handle only
the measurements generated while A and B are running. So essentially you
are guaranteed to loose some of the measurements during system startup and
shutdown. If that's the case, I would look in direction of PUB-SUB. You can
create a PUB socket per sensor in B and connect to it with a separate SUB
socket in each thread of A that need that particular sensor data. Or you
can create a single PUB socket in B and use different topics to distinguish
between the sensors. Each thread in A would then have a single SUB socket
and would subscribe to a set of topics depending on the sensor data it
requires.

Regards,
Mykola


вс, 19 авг. 2018 г. в 8:54, Michael Hansen <michaelsve...@gmail.com>:

> Ahh ok of course.
> This works much better.
> What if I have a setup where I in client A in reality have a lot of
> threads where each thread needs a type of stream of data and in B i have
> connected some sensors.
> These sensors needs to be streamed from B to A such that a group of
> threads needs sensor X another group of threads in A needs output of sensor
> Y etc.
> What would be the best type of architecture for this type of setup?
>
>
> On Sat, Aug 18, 2018, 10:03 Mykola Ostrovskyy via zeromq-dev <
> zeromq-dev@lists.zeromq.org> wrote:
>
>> Michael,
>>
>> ZMQ sockets are not thread safe. Each thread should use a separate
>> socket, so you need a pair of sockets in each test script.
>>
>> Also PAIR is a rather special-purpose type of socket mostly used in scope
>> of one process.
>>
>> I would recommend to use two PUSH-PULL channels for asynchronous
>> communication between peers. Something like:
>>
>> ClientA
>>   RecvThread
>>     recvsocket.bind(PULL, 9998)
>>   SendThread
>>     sendsocket.connect(PUSH, 9999)
>>
>> ClientB
>>   RecvThread
>>     recvsocket.bind(PULL, 9999)
>>   SendThread
>>     sendsocket.connect(PUSH, 9998)
>>
>>
>> Regards,
>> Mykola
>>
>>
>> сб, 18 авг. 2018 г. в 7:18, Michael Hansen <michaelsve...@gmail.com>:
>>
>>> Hi,
>>> I am not sure I see where there is missing some indentation.
>>> To me it looks okay regarding indentation.
>>> rtx is just a def with a while loop where recv is called and printed in
>>> every iteration.
>>>
>>> On Sat, Aug 18, 2018 at 12:44 AM, Tomer Eliyahu <tomereliya...@gmail.com
>>> > wrote:
>>>
>>>> Aren't you missing indentation in rtx functions?
>>>>
>>>> On Sat, Aug 18, 2018, 01:20 Michael Hansen <michaelsve...@gmail.com>
>>>> wrote:
>>>>
>>>>> Hello, I am quite new to ZMQ which seems like a really nice library.
>>>>> However i seem to be running into some issues already.
>>>>> I have to make a setup with just 2 peers who can send to each other.
>>>>> There is no order in how the clients communicate - however in generel
>>>>> data flows
>>>>> from one to the other and commands from the other to the first.
>>>>>
>>>>> I made a small test as below but communication seem to hang up and
>>>>> only one part is sending.
>>>>> Also - sometimes when i try to run this, i get the following error:
>>>>>
>>>>> 'Resource temporarily unavailable
>>>>> (bundled/zeromq/src/signaler.cpp:301)
>>>>>
>>>>> Abort trap: 6'
>>>>>
>>>>>
>>>>> Here are the 2 components, what am I doing wrong?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> # ==============
>>>>> # = SERVER A
>>>>> # ==============
>>>>>
>>>>>
>>>>> import threading
>>>>> import time
>>>>> import zmq
>>>>>
>>>>>
>>>>> port = 9999
>>>>> context = zmq.Context()
>>>>> socket = context.socket(zmq.PAIR)
>>>>> socket.connect("tcp://127.0.0.1:%s" % port)
>>>>>
>>>>>
>>>>> def rtx(socket):
>>>>> print('A started receiving...')
>>>>> while 1:
>>>>> print(b'A RECEIVED : %s' % socket.recv())
>>>>>
>>>>>
>>>>> def ttx(socket):
>>>>> print('A started transmitting...')
>>>>> while 1:
>>>>> socket.send(b'Message from A')
>>>>> time.sleep(1)
>>>>>
>>>>>
>>>>> threading.Thread(target=rtx, args=(socket,)).start()
>>>>> threading.Thread(target=ttx, args=(socket,)).start()
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> # ==============
>>>>> # = SERVER B
>>>>> # ==============
>>>>>
>>>>>
>>>>> import threading
>>>>> import time
>>>>> import zmq
>>>>>
>>>>>
>>>>> port = 9999
>>>>> context = zmq.Context()
>>>>> socket = context.socket(zmq.PAIR)
>>>>> socket.bind("tcp://127.0.0.1:%s" % port)
>>>>>
>>>>>
>>>>> def rtx(socket):
>>>>> print('B started receiving...')
>>>>> while 1:
>>>>> print(b'B RECEIVED : %s' % socket.recv())
>>>>>
>>>>>
>>>>> def ttx(socket):
>>>>> print('B started transmitting...')
>>>>> while 1:
>>>>> socket.send(b'Message from B')
>>>>> time.sleep(1)
>>>>>
>>>>>
>>>>> threading.Thread(target=rtx, args=(socket,)).start()
>>>>> threading.Thread(target=ttx, args=(socket,)).start()
>>>>>
>>>>> _______________________________________________
>>>>> zeromq-dev mailing list
>>>>> zeromq-dev@lists.zeromq.org
>>>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>>
>>>>
>>>> _______________________________________________
>>>> zeromq-dev mailing list
>>>> zeromq-dev@lists.zeromq.org
>>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>>
>>>>
>>> _______________________________________________
>>> zeromq-dev mailing list
>>> zeromq-dev@lists.zeromq.org
>>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>> _______________________________________________
>> zeromq-dev mailing list
>> zeromq-dev@lists.zeromq.org
>> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev@lists.zeromq.org
> https://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
https://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to