fredag 2 oktober 2009

Localhost settings for Android emulator

Recently I stumbled upon a problem when trying to connect to a local webservice through the Android emulator. Everytime I tried to connect it ended up with a "Connect refused" exception.

The answer to the problem and the solution is simple. What I was trying to do was to connect to "http://localhost:7001/myWebservice". The emulator interprets this as a connect to itself because it sees itself as localhost (of course :) ).

The solution? As Google states in their Android documenatation, http://developer.android.com/guide/developing/tools/emulator.html#emulatornetworking , the emulator runs behind a virtual router/firewall and you can reach the host loopback interface (127.0.0.1) by using the adress 10.0.2.2.

Inga kommentarer: