java.net.ConnectException - Connection Refused Android Emulator

我的梦境 提交于 2019-12-20 10:28:44

问题


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...


回答1:


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




回答2:


I got this figured out. If I use the internal ip it works fine (192.168.1.%) address.

Sorry for the wasted space here but maybe someone else will be able to use this.

the 127.0.0.1 is for the device (emulator) itself.




回答3:


instead of 'localhost' put your address (192.168.1.%)



来源:https://stackoverflow.com/questions/3497253/java-net-connectexception-connection-refused-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!