I would like to access a web service provided by one of the machines on my LAN from the android emulator.
If the service was running on the same machine where the em
Well, it just works (TM).
In the android emulator manual that I had read before testing (I try to RTFM before doing things) this is stated:
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.
This made me think that it could not access my LAN. I was wrong, just adding the IP of the server on my LAN allowed me to access it from the emulator.
As we know, emulator can access host machine by IP 10.0.2.2, so I tried IP forwarding but I could not make it working.. :|
I followed link below for forwarding request from localhost(10.0.2.2 in case of emulator) to the other machine in LAN.
http://www.debuntu.org/how-to-redirecting-network-traffic-a-new-ip-using-iptables
as of 2018-08 it seems the "it just works (TM)" certificate has been revoked
here is what I needed to access a server in my local network:
host ip (my pc): 192.168.15.102/24
server ip: 192.168.200.33/24
create a port forwarding rule in an elevated command prompt on host using netsh
netsh interface portproxy add v4tov4 listenport=80 connectport=80 connectaddress=192.168.200.33
start the mobile device emulator and browse to 10.0.2.2 (as mentioned in the documentation):
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
You could get an actual android device and connect it to the LAN (i have done this).
How are you connecting to the host machine? through html? because if your app requires a hard line connection to the machine then its not a very good solution for a mobile device.