连接失败:ECONNREFUSEDECONNREFUSED

2023-09-13 23:42:28 作者:戴着面具闯社会

我正在开发一个应用程序,一想我想要做的就是接收机器人从服务器数据库中的数据。于是我开始跑一些教程。我发现一个正在做pretty的很多我想要什么。 但我正在逐渐:

i am developing one app, and one 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) 

这torial全code是这里链接

Whole code of this torial is here link

发生错误:

OutputStreamWriter OUT =新OutputStreamWriter(connection.getOutputStream());

我检查:

在防火墙被禁用 在平正在 在连接字符串是完全一样的,当我运行的服务器管理界面中的servlet - 的http://本地主机:8080 /请求/ RQSRV -the servlet正在运行 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

我的配置:

服务器:玻璃鱼4.0 Android应用 - 在Eclipse开发 在Servlet的 - 在NetBeans开发

推荐答案

从Android模拟器访问PC本地主机,使用127.0.0.1的10.0.2.2代替。本地主机或127.0.0.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.

参考:http://developer.android.com/tools/devices/emulator.html#networkaddresses