1

I Have 2 applications:

  • a rails api running on my mac like this: rails s
  • an android client app talking with the rails api from mi phone

Well, the apps are not talking yet...

I'm trying to perform a POST to http://192.168.1.34:3000/api/uploads from the device, but I'm getting ERR_CONNECTION_REFUSEDon chrome.

So, I try to execute the same request from the computer and it returns the same ERR_CONNECTION_REFUSED.

When I execute http://localhost:3000/api/uploads, from the computer it works fine.

So, I think the local ip is not mapping to localhost. How can I do this?

I' using:

  • OSX El Capitan 10.11.1
  • Google Chorem Version 48.0.2564.23 beta (64-bit)

this is how my /etc/hosts file looks like:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       leansmac
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost

ping it's working too:

ping 192.168.1.34                                                                                                               
PING 192.168.1.34 (192.168.1.34): 56 data bytes
64 bytes from 192.168.1.34: icmp_seq=0 ttl=64 time=0.091 ms
64 bytes from 192.168.1.34: icmp_seq=1 ttl=64 time=0.070 ms
64 bytes from 192.168.1.34: icmp_seq=2 ttl=64 time=0.138 ms

the mac and the phone are connected to the same wifi

Kinlan
  • 16,315
  • 5
  • 56
  • 88
Leantraxxx
  • 4,506
  • 3
  • 38
  • 56

1 Answers1

2

I think it's an issue with Rails not accepting connections from outside except localhost.

Please try the following :

Allow public connections to local Ruby on Rails Development Server

The simplest way requires no additional installations: just add a single option to your rails server (or rails s) command when you start up the server:

rails s --binding=0.0.0.0

The 0.0.0.0 address means "listen to requests from anywhere." On many systems, the default is 127.0.0.1, which means "listen to requests from localhost only." (If you don't also specify a -p or --port option, then the port shall be 3000, as usual.)

Community
  • 1
  • 1
g90
  • 506
  • 3
  • 18
  • I know I can use the binding. I really want to do this: `http://my-app.192.168.1.34.xip.io/api/uploads.json` and does not work just adding the `--binding` option. I did not mention it, because I really want to access to `http://192.168.1.34:3000` like I did once (God knows when was that) – Leantraxxx Dec 04 '15 at 21:49
  • That shouldn't be too hard. I think this is the points are : 1. Your computer should resolve to my-app.192.168.1.34.xip.io. 2: Binding should be 0.0.0.0 and --port should be 80 – g90 Dec 04 '15 at 21:50
  • I'm using pow. I don't want to set anything. This is what I want: http://pow.cx/manual.html#section_2.1.5. I think my problem is not related with pow. Thats why I've simplified the question. Maybe was not a good idea... – Leantraxxx Dec 04 '15 at 21:57
  • Can you check steps from here : http://superuser.com/questions/299425/how-can-i-resolve-an-internal-ip-address-to-a-hostname-on-os-x/299431 nslookup http://my-app.192.168.1.34.xip.io – g90 Dec 04 '15 at 22:06