Ubuntu – Connecting to tomcat7 from android emulator

androidemulationnetworkingtomcat7

I can connect to apache server from chrome and firefox by typing 127.0.1.1:8080 and default page is shown, but when i type the same from my android emulator, no webpage is loaded, request timeout error, also if I try to connect via typing localhost this page is shown:

problem loading page
Firefox can't establish a connection to the server at localhost

What is wrong with my localhost?

I also tried 10.0.2.2 from android emulator, still can't connect.

What is wrong here? Is my localhost switched? How to fix it? Please help
Thanks

Best Answer

You can't see it because it is another localhost. To determine valid host's IP just ping your host's name from Android Emulator.

ping mukund

It should return you address like 192.168.X.Y or 10.0.X.Y. This is the correct address on which you should go with your browser.

Also, ifconfig should show you the external (as it seems to AE) IP of your machine:

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:03:99:8a:3b:ee  
          inet addr:10.0.0.125  Bcast:10.0.3.255  Mask:255.255.252.0
          inet6 addr: fe80::203:99ff:fe8a:3bee/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4579990 errors:0 dropped:1 overruns:1 frame:0
          TX packets:668167 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:880972560 (880.9 MB)  TX bytes:63991366 (63.9 MB)
          Interrupt:19 Base address:0x8c00 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:35718 errors:0 dropped:0 overruns:0 frame:0
          TX packets:35718 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:3293586 (3.2 MB)  TX bytes:3293586 (3.2 MB)

So, in my case, specifying 10.0.0.125:8080 in the AE should return the right page. The ifconfig command is also available in Android. Execute it to see the broadcast address of internal LAN.

And if you still can't determine your IP, execute this inside AE:

ping -b <broadcast>

It will return all available addresses. You should choose the one appropriate.

Related Question