Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect failed: ECONNREFUSED

I am developing one app, and what I think I wanna do is receive data from server database in android. So I started to run some tutorials. I found one that is doing pretty much what I want. But I am getting:

detailMessage   "failed to connect to localhost/127.0.0.1 (port 8080): connect failed: ECONNREFUSED (Connection refused)" (id=830021648792)  

Whole code of this tutorial is here link

Error occurs on :

OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());

I checked that:

  • firewall is disabled
  • ping is working
  • connection string is exactly the same as when I run the servlet from server admin interface - http://localhost:8080/Requestor/RQSRV -the servlet is running

My configuration :

  • Server : Glass Fish 4.0
  • Android App - Developed in Eclipse
  • Servlet - Developed in NetBeans
like image 481
Ján Srniček Avatar asked Aug 20 '13 17:08

Ján Srniček


People also ask

What does error connect Econnrefused?

ECONNREFUSED error means that connection could not be made with the target service (in your case localhost:8080 ). Check your service running on port 8080.

How do I fix error connect Econnrefused 127.0 0.1 8080?

You either need to start the server locally, since your request is going to localhost , or change localhost to the server´s URL or IP.

Why is my FTP connection refused?

A "Connection Refused" error means that either the server you're trying to connect to isn't running an FTP server, or there's a firewall in your way that's preventing the connection. An "User Authentication failed" error would usually occur if your credentials are bad.


1 Answers

To access your PC localhost from Android emulator, use 10.0.2.2 instead of 127.0.0.1. localhost or 127.0.0.1 refers to the emulated device itself, not the host the emulator is running on.

Reference: https://developer.android.com/studio/run/emulator-networking#networkaddresses

For Genymotion use: 10.0.3.2 instead of 10.0.2.2

like image 165
laalto Avatar answered Sep 21 '22 14:09

laalto