blog.christoffer.me

Hi, my name is Christoffer and I am an Internet addict.

2011-06-03 22:51

How to connect to your Google App Engine site from your Android emulator on localhost, without getting a ConnectException

If you are trying, from your Android application through the Android emulator, to access an external service on the same computer (such as your own Google App Engine site) by using the host name localhost or the IP-address 127.0.0.1, you might get a java.net.ConnectException: localhost/127.0.0.1:8888 - Connection refused error - even though you can perfectly well access the service outside the Android application.

The reason why a ConnectException occurs is because localhost or 127.0.0.1 inside the Android emulator is the emulator's own loopback interface, meaning all request sent to the destination will be looped backed to the emulator and won't actually be sent to your local machine.

To by pass this, simply replace localhost with the IP-address 10.0.2.2, as this is a special address towards the real local host. Done!

Old comments from Blogger

bbviana March 21, 2012 at 1:34 PM

Thanks!

comments powered by Disqus

Search the site

About Christoffer

Christoffer is a software and web developer, with more than 15 years experience of the Java language, now focusing on becoming a JavaScript Ninja.

Always interested in learning new and exciting new technologies and solutions within software- and web-development and the Internet, while suffering from the classic "I can't stop thinking" syndrome.

Currently working as a JavaScript Web Developer at QlikTech, while working on his own ideas and projects via his own software company during his spare time.

Please keep in mind that any opinions expressed here are Christoffer's own opinions and does not necessarily reflect those of his employer, or any other companies, organizations, groups or individuals.

Previous posts