Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.net.ConnectException: /127.0.0.1:8080 an android emulator

String url = "http://127.0.0.1:8080/SampleServlet/TestServlet?"; URL url = new URL(con_url);

run in android emualator. but i got the connectexception 02-20 13:05:08.745: ERROR/Server Connection(230): java.net.ConnectException: /127.0.0.1:8080 - Connection refused

please reply me

Thanks

like image 518
saravanan Avatar asked Feb 20 '10 08:02

saravanan


People also ask

What does Java net ConnectException mean?

java.net.ConnectException: Connection refused: connect is one of the most common networking exceptions in Java. This error comes when you are working with client-server architecture and trying to make TCP connection from the client to the server.

Why is 127.0 0.1 refused to connect?

0.1 (loopback address). So your client is trying to connect to any of the non-loopback addresses of your machine, while your server is listening only on the loopback address . So, no connection can be established. The solution to this problem is that connect to the same end point your server is listening on.

Is Java net ConnectException connection refused?

Ans: The Java connection refused is a case of a user trying to connect on TCP port but not able to access. There are many reasons, here are some possible causes why Java net ConnectException connection refused error occur: The server is not working. The client is not in the network.


1 Answers

127.0.0.1 is a Android emulated device's own loopback interface.

In other words, you connect to android emulated device (not to your computer) by using 127.0.0.1.

To get connection to your machine with web-server use 10.0.2.2 or real machine IP address (if you have direct access from web).

Use command ipconfig(Windows)/ifconfig(Linux) to obtain your IP address.

Also see official docs or this!

like image 57
Vlad Tsepelev Avatar answered Oct 26 '22 14:10

Vlad Tsepelev