connect failed: ECONNREFUSED

[亡魂溺海] 提交于 2019-11-26 19:11:11

问题


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

回答1:


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




回答2:


if you are using genymotion then go to command prompt type ipconfig -find for Ethernet adapter virtualBox host-only network: -find for Ipv4 Address..............192.1**.**.* copy

http://192.1..*/foldername/filename/filename.json or filename.php

to check if its working go to browser in emulator copy paste the url you should find the file which you are looking in your browser..

Sorry for English.. This worked for me hope this might help some one.. Thank u..



来源:https://stackoverflow.com/questions/18341652/connect-failed-econnrefused

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