Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Tuesday, July 26, 2016

why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client

why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


We normally use 10.0.2.2:(port number) in the url to connect to the local web server,but we should use the computer's ip address instead of 10.0.2.2

Then why do we use 10.0.2.2?

Answer by azertiti for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


If you use 10.0.2.2 for connection it will always point to your localhost. I used the real IP for my machine before reading this and it works in both ways.

The advantage of using 10.0.2.2 is that you don't care what is the real IP and you can move the project easier on another computer.

Answer by vlad_o for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


If you are running both server and emulator in you computer 127.0.0.1:(port) will refer to the emulator itself and not to the server.The 10.0.2.2 is the solution to that problem :)

Hope that helped

Answer by Andrew Allbright for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


The reason why you use 10.0.2.2 is because it's the special alias to your host loopback interface (aka 127.0.0.1). That's why it works, and isn't it cool that it does?

Answer by Zephyr for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


Network Address Space

Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.

The virtual router for each instance manages the 10.0.2/24 network address space ? all addresses managed by the router are in the form of 10.0.2., where is a number. Addresses within this space are pre-allocated by the emulator/router as follows:

Network Address Description

10.0.2.1    Router/gateway address  10.0.2.2    Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)  10.0.2.3    First DNS server  10.0.2.4 / 10.0.2.5 / 10.0.2.6  Optional second, third and fourth DNS server (if any)  10.0.2.15   The emulated device's own network/ethernet interface  127.0.0.1   The emulated device's own loopback interface  

Answer by ballu for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


10.0.2.2 is default ip address for your localhost.By using this ip in the url we can connect the local web server.
And also in the place of 10.0.2.2 we can use your local system's IP address also.(you can get this IP address type in google home page"What is my IP" then you get your IP).In that time you can get the same result.

Answer by sreedhar.appo for why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client


In the Place of 10.0.2.2 you can also use your system's Unique IP address. Here, 10.0.2.2 is default IP address to localhost.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.