Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to setup the android emulator to access the LAN of the host machine?

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 emulator is running (called host), I could add a network redirection and access the 10.0.2.2 (host loopback interface in the emulator) with the correct port.

However it is running on another machine on the LAN. I guess I could add another redirection on the host additionally to the above one (would have to fight with iptables though ... ), but does a more simple solution exist ?

like image 941
Longfield Avatar asked Jun 09 '10 21:06

Longfield


2 Answers

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.

like image 135
Longfield Avatar answered Sep 23 '22 05:09

Longfield


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

like image 22
tumbudu Avatar answered Sep 24 '22 05:09

tumbudu