java.net.ConnectException - Connection Refused Android Emulator

Kyle picture Kyle · Aug 16, 2010 · Viewed 29.6k times · Source

I have an android emulator I'm running from eclipse and just trying to connect to a simple socket server I wrote in .NET (c#).

The server is running on the same machine on port 4505. I am able to telnet (through PuTTy) to the server and it works just fine, but when I try to connect to the server with the android emulator I get a: java.net.ConnectException - localhost/127.0.0.1:4505 - Connection refused at org.apache.harmony.luni.net error.

I'm assuming this is because the emulator is on a different subnet or something? If that were the case though I would think I would be getting a different error that would be caught in the UnknownHostException catch block...

Answer

Grzegorz Gierlik picture Grzegorz Gierlik · Jan 5, 2011

According to Emulator Networking IP 10.0.2.2 should be used instead of localhost/127.0.0.1.