Friday 22 July 2011

Android: connecting to localhost

To connect the emulator to localhost, the urls...

"http://localhost:" + portNumber + "/" + subDirectoryName
"http://127.0.0.1:" + portNumber + "/" + subDirectoryName

... won't work. Use instead...

"http://10.0.2.2:" + portNumber + "/" + subDirectoryName


For more info on this, see the Android developer Using the Android Emulator page, Emulator Networking section:
http://developer.android.com/guide/developing/devices/emulator.html#networkaddresses

No comments: