I have an app running on my computer at 127.0.0.1:3000
I would like to access that app from an iPhone connected to the same network. I have done this before but blanking out on how I did it. Any ideas?
I have an app running on my computer at 127.0.0.1:3000
I would like to access that app from an iPhone connected to the same network. I have done this before but blanking out on how I did it. Any ideas?
First you need to determine the ip address or name of the machine you are running the webserver on. I'm assuming you are running the webserver on a mac since you tagged your post macosx
athough the instructions are similar for linux machines. So, on your mac:
Terminal.app
. It's under Applications->Utilities
.ifconfig
in the terminal. That shows you all the network interfaces on the machine. One of them is the network your machine is actively connected to. If you mac is on a wired connection that should be en0
. Make a note of the address after inet
- that should be the address your machine uses.
nc -v 192.168.10.1 3000
. (replace 3000 with the port your application is running on)
Connection to 192.168.10.1 3000 port [tcp/http] succeeded!
.ctrl-C
to exit the nc session.If you are unable to connect to your application on the server's real address, that means your application isn't listening on that address. You will need to investigate how to change your application configuration to modify that behavior. Since I don't know what application you are running I can't offer any good ideas on that.
Find the name of your Mac using hostname
(at the Terminal prompt) and use that in your URL. E.g. http://Tonys-iMac.local:3000/
If for some reason Bonjour doesn't work in your environment, find the address of the Airport on an iMac or MacBook with
ipconfig getifaddr en1
or in general with
ipconfig getifaddr $(route -n get default|awk '/interface/ { print $2 }')
Basically, from firewall settings you can allow a certain application (e.g. ruby) to accept incoming connections. Plus to allow access to the outside world (e.g www), you'll need to forward traffic to your internal gateway:port via your router settings.
Here's how to do this:
Open a port on the router (via 192.168.1.1) to forward traffic from your_web_ip:port to a local_gateway:port
Done. Now from the remote computer, open your browser to your web ip address (find via http://www.whatismyip.com/) + destination port# above, e.g. 72.189.194.65:3280, this will connect to your local 192.168.1.4:3000
Note: I'm running on Mac OSX 10.7.5
If the application is listening on 127.0.0.1:3000 only then you can't access it from another computer. To do so you would need to modify the configuration to Listen the IP or 0.0.0.0 (all available interfaces).Thats option one.
The second option is to use a proxy.
Third option is if you can ssh from the iphone you can also use ssh forwarding.
ssh user@host -L 3000:127.0.0.1:3000
Then on your iphone open 127.0.0.1:3000
127.0.0.1 is the local address every computer has for itself. You have to find out what the real IP address (or Host/Bonjour name) of the machine is. Go to System Preferences, Network and look up the IP of the machine, either for the Ethernet port if you use a cable or the Airport if you use WLAN . Then open this address together with the :3000 part in Safari on the iPhone.