jeffbass / imagezmq

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

Add PUB/SUB ZMQ mode to the library #14

Closed bigdaddymax closed 5 years ago

bigdaddymax commented 5 years ago

The first part: code only.

All changes are nonbreaking, should not change existing codes behavior.

Changes to ImageSender

Changes to ImageHub

Confusing point

When creating ImageSender and ImageHub with block = False pay attention to socket settings. Probably, there is a better and cleaner solution, however, this implementation allows to avoid breaking existing projects.


#Current functionality/blocking mode
    sender = imagezmq.ImageSender(connect_to='tcp://127.0.0.1:5555' )
    .....
    receiver = imagezmq.ImageHub(open_port='tcp://*:5555')

#New feature/Non-blocking mode
    sender   = imagezmq.ImageSender(connect_to='tcp://*:5555', block = False)
    .....
    receiver = imagezmq.ImageHub(open_port='tcp://localhost:5555', block = False)
jeffbass commented 5 years ago

Thanks for your pull request. I am going to create a new branch "add-pub-sub" to allow testing and refinement of your code. I should have the new branch created in a few days, and will send you instructions on how to move your pull requests to that branch. Thanks for your patience!

jeffbass commented 5 years ago

I've added a feature branch named "add-pub-sub" to the imagezmq repository. Could you please move your pull request to that branch? Instructions here.. I believe adding PUB/SUB is a useful feature and I appreciate your contribution. Let's develop your contribution in the "add-pub-sub" branch until it is refined and tested. After development and testing, I will merge it to the master branch. Thanks!

bigdaddymax commented 5 years ago

I have changed the base to "add-pub-sub" branch.

I am working on a set of test scripts for PUB/SUB pattern, hope to get it done within a few days.

Thank you!

jeffbass commented 5 years ago

Thanks! I was going to suggest tests scripts as the next step, before we got further with the actual code changes. Please put the test scripts in the "tests" folder in a single file named test_pub_sub.py. My preferred working style for this library is 1) open feature branch 2) build test scripts, 3) build docs, 4) develop code 5) test code against test scripts and then iterate. Thanks again for being a contributor to the library; I will add you to a contributors list in the main README.rst. I am going to add the "preferred working style" list as well. I should have done that already.

bigdaddymax commented 5 years ago

This is a great suggestion, let me try to apply those changes.

This is one of my very first experiments with Python so be ready that my next fix will be pretty far from ideal as well. But I would like to come to an acceptable solution at the end with your help.

I really appreciate all your comments and suggestions.

bigdaddymax commented 5 years ago

Hi Jeff, I have added simple examples (tests/test_1_pub.py and tests/test_1_sub.py), also modified a little bit tests/test_1_send_images.py and tests/test_1_receive_images.py scripts to demonstrate the difference between the two modes.

Also, modified the module itself according to your suggestions.

Could you please review and comment on what else should be changed?

Next step will be to add a little bit more complex tests/examples.

Thanks.

jeffbass commented 5 years ago

This looks good. It looks like you have done a good job of incorporating all my requested changes. And you have improved and cleaned up some of the other code. Thanks! I will review this for a couple of days and merge it to our add-pub-sub branch. I will make some further changes that you can pull and change / review. We can iterate from there. Thanks again for your contribution. This is good work. Jeff