Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't init multiple sender with same connect_to #51

Open
huyker opened this issue Oct 19, 2020 · 1 comment
Open

Can't init multiple sender with same connect_to #51

huyker opened this issue Oct 19, 2020 · 1 comment

Comments

@huyker
Copy link

huyker commented Oct 19, 2020

Hello,
I have a question. Can i create multiple Sender connect_to same address in 1 PC( localhost) and only 1 Hub get it?
I want to use Pub/Sub mode like this image

@jeffbass
Copy link
Owner

Hi @huyker,
Yes, you can use multiple Senders to send to a single Hub using PUB/SUB. The Hub will have to subscribe to each sender with the sender's specific TCP address. The Senders (Publishers) do not need to know the address of the Hub.

For your 3 Senders (Publishers), the ImageSender instantiation code looks like this:

# Each of your 3 senders must allow subscribers from any tcp address, port 5555
sender = imagezmq.ImageSender(connect_to='tcp://*:5555', REQ_REP=False)  # same in all 3 Senders

Note that the above connect_to= is exactly the same on all 3 Senders. Senders in PUB/SUB mode do NOT specify the address of the Hub / Subscriber.

For the Hub (Subscriber), the Hub instantiation code needs to specify the exact TCP address of every sender. For Sender 1, this is specified in the ImageHub instantiation. For Sender 2 and Sender 3, the ImageHub.connect() method is used:

# Instantiate ImageHub and provide the first sender / publisher address
image_hub = imagezmq.ImageHub(open_port='tcp://192.168.86.39:5555', REQ_REP=False)

# Then, use the connect() method to connect to sender / publisher 2 and 3
image_hub.connect('tcp://192.168.86.38:5555')  # connect to second sender / publisher address 
image_hub.connect('tcp://192.168.86.42:5555')  # connect to third sender / publisher address

There is a pair of example programs demonstrating this in the imageZMQ examples folder:

  • ImageSender PUB program (this will be the same for all 3 senders) example.
  • ImageHub SUB program (it shows how to subscribe / connect to multiple senders) example.

The imageZMQ API has details about the connect method here. See line 72.

Let me know if this works for you or if you have any questions,
Jeff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants