My Android application talks to a php server. I have Apache/php running locally on WAMP Server. I am running Windows 7. If I go to localhost on Windows 7 the site shows b
Indeed for a local network you should use your local ip-address (e.g. 192.168.1.x). Do not forget to open up your port (mostly 80) in you Windows firewall settings.
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
Also note that the address 127.0.0.1 on your development machine corresponds to the emulator’s own loopback interface. If you want to access services running on your development machine’s loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.
For more detail, please check http://red23rockets.com/?p=28
In general, you can't.
What you can do, if the computer is on the same wireless network as the Android device, is connect to the computer's internal IP. For example, on a typical home wifi router, the router is at 192.168.1.1
, and the devices connected to it are 192.168.1.x
. So if your Windows 7 PC is at 192.168.1.5
, you should be able to access this from your Android device just fine...
Open terminal and type for Unix(Ubuntu) : ifconfig or ipconfig for Windows and you are going to see :
Jon is correct that in the general case you cannot make the android device connect to a pc through the usb cable (a major difference from the android emulator where such connection is accomplished by an alias address). However, there are some things you can do:
You can connect both the pc and the phone to a secured wifi router. It doesn't even need to have an upstream internet connection.
Apparently, if you have froyo and the usb tethering option, turning this on will as a side effect establish networking over USB that allows the phone to contact the pc (just watch where you pc's internet traffic is going though)
If you wanted something on the pc to open a connection to something listening on the phone, you could use an adb port forward. But it sounds like you want a client on the pc to contact a server on the phone, so that won't work.