Localhost Access in Android Emulator

This is a small tit-bit I discovered today:


If you want to access your localhost through the Android Emulator - you need to use the IP Address 10.0.2.2 unlike how we do on the web browsers on our desktops where we access the local host as 127.0.0.1 or 'localhost' itself.


This information is useful if for testing purposes you have locally installed a webserver and put a few HTML pages or if you have locally hosted web services - say REST Services that need to be invoked through a URL like this: http://localhost:8080/rest/hello, then, use the above mentioned IP address and you will be able to access your service or webpage through the emulator.


Or you could simple use your own IP address like 192.168.3.233 - whatever yours is. If you do a "ipconfig" in a windows command prompt, you will know what your IP address is. (one of the ways to find it out). However, there is one disadvantage with this method if your IP is allocated to you dynamically on your network. This will keep changing. In such a case, using 10.0.2.2 will be the equivalent of 127.0.0.1 which will not change for the localhost.

Search & Download lots of Eclipse-Android Tutorials:-
  Using Pdf Wallet you can find useful and free Android Tutorials.


Search 

Please Select File-Format

PDF  - eBooks in pdf format.
PPT  - Presentations:2003.
PPTX- Presentations:2007+.
DOC - Microsoft Word Files:2003.
DOCXMicrosoft Word Files:2007+.
XLS  - Excel File format:2003.
XLSX - Excel File Format:2007+.
CHM - Compiled Help Files.
RTF  - Rich Text format.
TXT  - Text Files. 

No comments:

Post a Comment