Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

java - 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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...