Tim Koelkebeck
Tim Koelkebeck

Reputation: 815

how to connect to webrick from different computer

This question has been asked a few times before on stack overflow and I've tried the various recommendations but still can't get it working.

I'm on OSX 10.11, home wifi network, using Chrome. If I boot webrick with the following:

rails server -b 0.0.0.0

The server starts and I can access my app via http://0.0.0.0:3000/ on the same computer but from a different computer (also an up-to-date OSX on the same wifi network) I get an ERR_CONNECTION_REFUSED.

whatismyip.com says my IP is 76.14.66.137. When I try any of the following

rails s -b 76.14.66.137
rails s -b 76.14.66.137 -p 80
rails s -b 76.14.66.137 -p 3000
rails s -b 76.14.66.137 -p 3002

I get the same error every time: Can't assign requested address - bind(2) for 76.14.66.137:80 (Errno::EADDRNOTAVAIL)

Is there an OSX setting that I may need to change? What am I doing wrong?

Upvotes: 0

Views: 389

Answers (1)

axvm
axvm

Reputation: 2113

0.0.0.0 means to listen all network interfaces.

https://www.whatismyip.com/ gives you the router's external IP. This is not the IP you would use to connect to your local server with a separate local machine. You need to get your machine's real, internal IP address. (On OSX this is easy, just open Network Preferences and your internal IP is listed at the top under "Status: Connected". You can also find the IP by logging into your router adminstration.) Let's say your machine running the rails server has an internal IP of 191.166.0.100.

So you would start your local server with 0.0.0.0 ip address on machine A. Then on machine B you would connect to http://191.166.0.100:3000.. machine A's interal IP. Then you will get response from your rails app. If not then you need to check out server firewall settings and router settings.

Upvotes: 2

Related Questions