jeffbass / imagezmq

A set of Python classes that transport OpenCV images from one computer to another using PyZMQ messaging.
MIT License
1.01k stars 160 forks source link

REQ/RESP One sender multiple recievers #77

Open alejoGT1202 opened 1 year ago

alejoGT1202 commented 1 year ago

Hello,

I would like to know if it's possible to do the following using the REQ/RESP approach instead of PUB/SUB.

I have one device that will be transmitting the images, and I two separate devices that will be processing the images. I would like to send images to both devices only when both of them already finished they respective processes, would it this be possible? Thanks for the help.

jeffbass commented 1 year ago

You cannot have multiple RESP receivers for a single REQ sender. The REQ / RESP pattern connects the REQ image sender to one and only one RESP image receiver. It is a consequence of the ZMQ REQ /REP pattern design.

There are 2 ways I can think of to handle sending images from one image sender to multiple image receivers:

  1. Use PUB / SUB instead of REQ / REP. The ZMQ design for PUB / SUB allows multiple subscribers to a single sender.
  2. Set up the REQ image sender with 2 REQ / REP connections, each one with a separate imageZMQ.ImageSender() / imageZMQ.ImageHub() pair connecting to the single REP image receiver. You would need to send each image twice: once using the first connection and then again using the second connection. That would take twice as long per image for transmission, which is likely to be problematic.

You could also use one of the other ZMQ patterns for REQ / REP described in Chapter 3 of the ZMQ Guide. If you do that you would need to write your own code to replace imageZMQ since it does not implement any of these more advanced ZMQ patterns. While the imageZMQ code could be used as a starting point, using the more advanced ZMQ patterns for REQ/REP is likely to be a substantial undertaking.