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, th
USB doesn't provide network to mobile device.
If both your desktop and phone are connected to the same WiFi (or any other local network), then use your desktop IP address assigned by the router (not localhost
and not 127.0.0.1
).
To find out the IP address of your desktop:
ipconfig
(Windows) or ifconfig
(Unix)
ifconfig | grep "inet " | grep -v 127.0.0.1
will yield only the important stufflocalhost
and 127.0.0.1
)If your phone is connected to the mobile network, then things are going to be harder.
Either go hardcore:
<your desktop IP>:<server port number>
Otherwise use something like xip.io or ngrok.
NOTE: The ifconfig
command has been deprecated and thus missing by default on Debian Linux, starting from Debian stretch. The new and recommended alternative for examining a network configuration on Debian Linux is ip command. For example to use ip command to display a network configuration run the following:
ip address
The above ip command can be abbreviated to:
ip a
If you still prefer to use ifconfig
as part of your daily sys admin routine, you can easily install it as part of the net-tools
package.
apt-get install net-tools
Reference is here
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 :-
hostname -i
#127.0.0.1
hostname -I
#198.168.*.*
Try going to this file:
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
# onlineoffline tag - don't remove
Order Deny,Allow
Allow from all // change it Deny
Allow from 127.0.0.1
And change 10.0.2.2 to your IP address.
finally done in Ubuntu , i am running nodejs server on localhost:8080
1) open terminal type ifconfig you will get ip something like this : inet addr:192.168.43.17
2) now simply put url address like this : "192.168.43.17:8080" (8080 port coming from localhost port number) ex : "192.168.43.17:8080/fetch"
Although one answer has been accepted but this worked for me:
ifconfig
inside terminal and look for en0/en1 -> inet
it should be something like 19*.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 is 1**.1**.15*.2**
1**.1**.15*.2**:port/
from your mobile device.It is as simple as this.
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):
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.1.65
Allow from ::1
Allow from localhost
One could extend this to include an entire sub domain too for e.g. 192.168.1.0/24 etc