I'm able to access my laptop web server using the Android emulator, I'm using 10.0.2.2:portno
works well.
But when I connect my real Android phone, the phone browser can't connect to the same web server on my laptop. The phone is connected to the laptop using a USB cable. If I run the adb devices command, I can see my phone.
What am I missing?
The easier way to default localhost is to use http://localhost:port. This works in a laptop and Android as well.
If it does not work, then in android set the default IP of your phone to 127.0.0.1:port :)
Open terminal and type :-
Although one answer has been accepted but this worked for me:
ifconfig
inside terminal and look foren0/en1 -> inet
it should be something like19*.16*.1.4
.) (on windows, use `ipconfig)Open your mobile settings and go to network-> long press your wifi network-> modify network -> scroll down to advanced options -> chose proxy manual and in proxy hostname type your address i.e.
19*.16*.1.4
inside port enter your port. and save it.search for
what is my ip
in google chrome, and get your ip, lets say it is1**.1**.15*.2**
1**.1**.15*.2**:port/
from your mobile device.It is as simple as this.
I found a quick solution to this problem. Try this link. It should help you fix the problem.
I only changed one thing, where the tutorial states you change '127.0.0.1' to 'All', change it to the IP address your server is running on instead.
After that, you should be able to connect to your localhost.
Below is a (proofread) copy of the information from the linked page:
Step 1
Install the Wamp server (or any other you prefer).
This is one of the best servers I know to set up a local server. If you have installed Apache or any other server, ignore this step.
Download and install Wamp Server from here.
Step 2
Add a new rule for port 80 in Windows Firewall.
Open the Control Panel and select Windows Firewall.
Select Advanced settings from the left panel of the Windows Firewall setting page.
Select Inbound Rules from the left panel, then select New Rule.
Select Port and click Next.
Select the “Specific local ports” radio button and enter 80 as the port value.
Keep Allow the connection unchanged and move to the next step.
Keep Profile options unchanged and click Next.
Give some nice name to your new rule and click Finish.
This will enable port 80 access on local network IP.
Step 3
Edit the httpd.conf file of the Wamp server to fix the 403 error.
We need to edit this file. Otherwise, we will get the 403 forbidden error when we access the localhost through a local network IP.
Click on the Wamp server tray icon.
Open Apache server sub menu.
Select httpd.conf.
Find this section of configuration in the httpd.conf file:
Find and replace ‘127.0.0.1’ with ‘All’, save the file, and restart your Wamp server.
Step 4
Find your local network IP.
Open the command prompt.
Type and enter the
ipconfig
command.In my case, my local area network address is 10.0.0.2.
This is the IP which you need to access your localhost on your Android phone over wifi. To test if it is working, type this IP address in your desktop browser where your localhost server is installed. The browser should display your localhost page successfully. This will assure that this local network IP is now successfully accessible on your Android phone.
I hope this tutorial will help you to access your localhost over wifi.
A solution to connect my mobile device to my wamp server based on my laptop:
First, wifi is not a router. So to connect my mobile device to my wamp server based on localhost on my laptop, I need a router. I have downloaded and installed a free virtual router: https://virtualrouter.codeplex.com/
Configuring it is really simple:
Then you can connect to your laptop via your device by launching a browser and fill the IPV4 address of your laptop (to find it on windows, type in cmd : ipconfig, and find ipv4 address)
You should see your wamp server home page.
On Windows PC You may not need to do anything else than finding out your IPv4 Address using "ipconfig" command.
Other Env Details : Windows 7, Google Nexus 4 (4.2.2), Tomcat Server, Grails Application.
You should also make sure that you have the permission to access internet in AndroidManifest file :
As this is an old question, there is a new way to do this that is really really simple. Download the ADB Chrome Extension and then follow these instructions:
https://developers.google.com/chrome-developer-tools/docs/remote-debugging