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
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With