Spacebrew / spacebrew

A dynamic re-routable software toolkit for choreographing interactive spaces.
MIT License
222 stars 50 forks source link

Connection between Publisher & Subscriber lost when IP changes #59

Open aabm00 opened 9 years ago

aabm00 commented 9 years ago

Hello

I have my own Spacebrew server installed in Heroku and I have tried the button example and it works fine (changing the color background). The problem comes when my laptop's external IP, changes, For example from 10.179.151.165 to 10.231.195.45. Then I can see two version of the same button and the connection between publisher and subscriber is lost (In the same button) so when I press the button, the background color doesn't change.

There are something I have missed?

Thanks

willwnekowicz commented 9 years ago

Spacebrew uses both the publisher/subscriber name and its IP address to identify the endpoint. You might want to setup a static IP address on your laptop, or setup a script to bootstrap the connections using the admin API.

aabm00 commented 9 years ago

Hello thanks for your answer.

I will be more explicit in the way I want to use the Spacebrew:

I will have different ArduinoYun boards connected via Wifi, behind a router in differents locations (they can be even different cities) sending sensors information to the Spacebrew server. They will be the Publishers. On the other hand there will be other clients that will receive and work with the data (Subscribers). They will be connected through the Spacebrew Admin utility.

So, the information flow will be constant and can't lost the connection between Publishers and Subscribers when the Public IP of them changes.

I have made a test to check what the public IP are:

1 - I have checked my public IP in internet (the router) a is 77.211.58.145

2- I have connected 2 button examples and the Admin to the spacebrew server sandbox.spacebrew.cc and I got that the IP of the 2 buttons are 77.211.58.145. This has sense

3- I have connected 2 button examples and the Admin to my own server in Heroku and I get that the IP of the 2 buttons are 10.99.161.33 and 10.13.189.201. This hasn't sense

The buttons work in both servers, but the difference is that in mine the IPs change every hour losting the connections between Publishers & Subscribers and on the other hand the buttons in the Spacebrew server remains stable.

The questions would be:

1- Why the the buttons connected with the Spacebrew server, get the Public IP of my router and the ones with my server get private IP when the Spacebrew's admin utility in both cases are running locally in my computer?

2- What I have to do to get my own server, working as the Spacebrew server?

3- Could you give more details about setup a script to bootstrap the connections using the admin API? because give an static publicIP is not an option because can be a lot of Yun boards sending information.

Thanks

mangtronix commented 8 years ago

I have the same problem for a similar use case, where my Spacebrew clients are behind a router whose IP address changes.

  1. Heroku uses load balancers, so you're probably seeing the private IP address of the load balancers inside Heroku. Basically your Spacebrew client connects to the load balancer, then the load balancer connects to the Spacebrew server. Some more info here http://stackoverflow.com/questions/18264304/get-clients-real-ip-address-on-heroku
  2. https://groups.google.com/forum/#!topic/spacebrew-cc/g_096UBjEgo
  3. I think I found a solution using the existing tools. You can use the persistent admin command-line tool to maintain the connection between clients based on string matching.

https://github.com/Spacebrew/spacebrew/blob/9da52111c981c908d962ef05e49d6a6cc9368c71/README.md#command-line-persistent-admin

For example, to connect all publish routes named "slider1" to all receive routes named "slider2" on the Spacebrew server running on localhost:

$ node node_persistent_admin.js --host localhost
This is a CLI admin for maintaining persistent routes in a spacebrew network.
commands:
  ls, add, remove, save, load, help, exit
connected
################ added a client
add .*,slider1,.*,slider2
added persistent route
ls
publishers:
  0: cloudSlider, slider1
  1: cloudSlider, slider2
  2: cloudSlider, slider3
subscribers:
  3: cloudSlider, slider1
  4: cloudSlider, slider2
  5: cloudSlider, slider3
persistent routes:
  0: .*,slider1 -> .*,slider2
save
config saved to persistent_config.json

node_persistent_admin.js is actually an admin client to the Spacebrew server, so you have to keep it running separately from the server. When the persistent admin is running it watches connections to the Spacebrew server and makes connections between the clients based on the persistent routes (string matching on the client and route names).

quinkennedy commented 8 years ago

The node_persistent_admin is designed for this sort of use case. You would run that script after the Spacebrew server is already running, and then use the CLI to set up the persistent routes you want. I believe it loads from a file at start up, so you can configure it once, write the file, and not have to configure it again. On Jan 26, 2016 8:17 AM, "Michael Ang" notifications@github.com wrote:

I have the same problem for a similar use case, where my Spacebrew clients are behind a router whose IP address changes.

1.

Heroku uses load balancers, so you're probably seeing the private IP address of the load balancers inside Heroku. Basically your Spacebrew client connects to the load balancer, then the load balancer connects to the Spacebrew server. Some more info here http://stackoverflow.com/questions/18264304/get-clients-real-ip-address-on-heroku 2.

https://groups.google.com/forum/#!topic/spacebrew-cc/g_096UBjEgo 3.

I'm looking for a solution for this too! One way might be to run a server with a modified version of this script so that it matches the connections only using the name and ignores the address. https://github.com/Spacebrew/spacebrew/blob/master/spacebrew_live_persist.js#L165

There's also this "node_persistent_admin.js" that might already do that. https://github.com/Spacebrew/spacebrew/blob/master/node_persistent_admin.js

— Reply to this email directly or view it on GitHub https://github.com/Spacebrew/spacebrew/issues/59#issuecomment-175097940.

mangtronix commented 8 years ago

Thanks! Yes, node_persistent_admin loads the persistent routes at startup. But first you have to manually save the routes (with "save") in the CLI. I added an example in my comment above.

hgodinho commented 7 years ago

Hello! Im having some troubles in there. My application is running on: http://spacebrew.github.io/spacebrew/admin/admin.html?server=gertrudes.herokuapp.com&port=80 When starts the application runs properly, but after a while the connections node get lost, it only get back when I refresh the admin page on browser.

When I try to run "node_persistent_admin.js" I get an error in CLI:

Error: connect ECONNREFUSED 127.0.0.1:9000 at Object.exports._errnoException at exports._exceptionWithHostPort at TCPConnectWrap.afterConnect [as complete] code: 'ECONNREFUSED'. errno: 'ECONNREFUSED', syscall: 'connect', adreess: '127.0.0.1', port: 9000

What Im doing wrong?