Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

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?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.<xx>, where <xx> 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...