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?
First of all connect your phone and computer to common wifi.
Then, open command prompt using run as administrator
Give ipconfig command
Which shows wireless lan ip
Use ip:port of your server to access in phone
ngrok lets you put your localhost onto a temporary server and is very simple to set up. I've provided some steps here that can be found in the link:
ngrok http [port number]
You'll see a little dashboard in your terminal with an address pointing to your localhost. Point your app to that address and build to your device.
EASIEST way (this worked flawlessly for me) is to locally host your site at
0.0.0.0:<port_no>
and to access it using mobile devices, use<local_ipv4_address>:<port_no>/<path>
in browser.ipconfig
in cmdmac osx users
i had success by enabling remote management:
You will see a message similar to this
On your android device you should now be able to hit
some.url.com
, which delegates tolocalhost
on your mac. You can also useifconfig
to get the ip of your macbookportable solution with ngrok (any OS with node or npm)
If you don't mind exposing your project with a temporary domain you can use
ngrok
. Lets say I have an app that runs onlocalhost:9460
This will give me:
I can now reach
https://f7c23d14.ngrok.io
as a way to remotely view localhost. This is great to share design work or progress with clientsalternate solution with nginx proxy pass
If you are running something like this through nginx proxy_pass it will require a bit more tweaking - this is a hacky approach, but it works for me and i am open to suggestions on improving it:
81
as opposed to80
sudo nginx -s reload
http://youripaddress:81
```
reload and visit
http://youripaddress:81
"Port forwarding on Chrome for Android makes it easy to test your development site on mobile. It works by creating a listening TCP port on your mobile device that maps to a particular TCP port on your development machine. Traffic between these ports travels through USB, so the connection doesn't depend on your network configuration."
More details here: https://developer.chrome.com/devtools/docs/remote-debugging#port-forwarding
This is what worked for me, I added another line after the 127.0.0.1 ip to specify the exact local network ip address (not the public ip address) of the device I wanted to use. In my case my Samsung Galaxy S3
As suggested by Bangptit edit the httpd.conf file (x being the version numbers): C:\wamp\bin\apache\Apache2.x.x\conf\httpd.conf
Search for the onlineoffline tag and add the ip of your phone (I found my phones ip address in my routers configuration pages):
onlineoffline tag - don't remove
my phones ip in the line below
One could extend this to include an entire sub domain too for e.g. 192.168.1.0/24 etc