jeffbass / imagezmq

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

Does ImageZMQ works with remote servers not on the same network? #75

Open Ebdulmomen1 opened 2 years ago

Ebdulmomen1 commented 2 years ago

Hi Jeff, hope you're doing well, I wondered if I could stream video from multiple clients to a remote server on another network?

jeffbass commented 2 years ago

Hi @Ebdulmomen1, I'm doing well, thanks!

Yes, multiple senders to a receiver on another network works fine. I use multiple senders and multiple networks in my own Yin Yang Ranch setup. I suggest you do your testing of senders and receiver on one network, then expand testing to a 2nd network, etc. Here is a sequence that I have found to be helpful:

  1. Get your image sending & receiving working with a one image sender and one image receiver. How you do this is slightly different for REQ/REP versus PUB/SUB. There is documentation and some examples in this repository to help with that. Do this first step with one image sender and one image receiver on a single network. Use simple test programs to start the process; you can enlarge your sending and receiving programs one you have all the ports, etc. working.
  2. Keep same image receiver & add a second image sender; again, keeping all 3 computers on the same network.
  3. Replicate the image receiver code that worked in the one-network setup onto your server on the "other network". Then send from a single image sender to that new image receiver. Verify it works. If it doesn't, be sure you get both the IP address and the port correct. Be sure you have the port open through any firewall or port forwarding for both sending and receiving on your remote network. Be sure that your sender network also is able to send images and receive replies with appropriate port forwarding or firewall settings. ZMQ needs to have the port open for both sending and receiving on both the sender and the receiver in order for it to do its handshaking to set up the connection. Getting ports and IP addresses correct across networks and firewalls, etc. can be quite tricky and often involves a lot of trial and error.
  4. Finally, add a second image sender and make sure your receiver gets those images, too.
  5. Then you can add more senders and add more "real code" to your simple test programs.

Port forwarding and setting firewall ports for in and out can be quite challenging. Every network combination is different, but a way through can be found if you have IP addresses and ports set up correctly. Always test with the smallest possible sending and receiving programs before make your programs more complex.

Let me know if you try this and run into difficulties. Also, if you have additional questions, show me a snippet of your sending and receiving code that show whether you are using REQ/REP or PUB/SUB.

Jeff

Ebdulmomen1 commented 2 years ago

Hi Jeff, thank you for the detailed answer, I did some tests and got it working using ssh tunneling by Ngrok(since I don't have a public IP), I will share the complete example with a detailed description of my case when I find some time if you would like maybe you could even add it to the docs for people who want to get it working on different networks even though their ISP doesn't offer a public IP (I'm in Iraq, this is a common case), Thank you again!

jeffbass commented 2 years ago

Hi @Ebdulmomen1, thanks for the update. I would appreciate your sharing a complete example description when you have time. I will definitely include it in the imageZMQ docs. I think it would work well to have it be a separate document titled "Using imageZMQ with external networks and firewalls" with a link to it in "Additional Documentation and Examples" section of the main README.rst. A documentation file named "external-networks.rst" in the docs folder would work well. Feel free to write a draft and send a pull request if you have time and interest to do so. Or just put a description in this thread and I will create the file. Thanks!

OctaM commented 2 years ago

@Ebdulmomen1 any update on how you manage to use imageZMQ with external networks and firewalls? Thanks