java.net.ConnectException:无法连接到/192.168.253.3(端口2468):连接失败:ECONNREFUSED(连接被拒绝) [英] java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused)
问题描述
我要转移个人电脑和手机有WIFI之间的一些数据,但我得到了java.net.ConnectException:无法连接到/192.168.253.3(端口2468):连接失败:ECONNREFUSED(连接被拒绝)当我运行我的Android项目。
I want to transfer some data between PC and a mobile phone with wifi, but I got "java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused)" when I run my android project.
这是我得到的WiFi IP地址:
This is how I get the wifi ip address:
String ip = String.format(
"%d.%d.%d.%d",
(wifiInfo.getIpAddress() & 0xff),
(wifiInfo.getIpAddress() >> 8 & 0xff),
(wifiInfo.getIpAddress() >> 16 & 0xff),
(wifiInfo.getIpAddress() >> 24 & 0xff));
new Recive().execute(ip);
这是有关将消息发送到PC code:
This is the code about sending a message to the PC:
Socket socket = null;
String message = "test\r\n";
protected Void doInBackground(String... urls) {
try {
Log.i("ip", urls[0]);
socket = new Socket(urls[0], 2468);
toserver = new DataOutputStream(socket.getOutputStream());
toserver.writeBytes(message);
toserver.flush();
toserver.close();
socket.close();
return null;
} catch (Exception e) {
Log.i("e", e.toString());
return null;
}
}
但出现错误,
java.net.ConnectException: failed to connect to /192.168.253.3 (port 2468): connect failed: ECONNREFUSED (Connection refused)
另外,我使用的是Android手机上运行的应用程序。
Besides, I use a android phone to run the app.
推荐答案
一个连接失败:ECONNREFUSED(连接被拒绝)很可能意味着,没有什么监听端口和IP地址。可能的解释包括:
A "connect failed: ECONNREFUSED (Connection refused)" most likely means that there is nothing listening on that port AND that IP address. Possible explanations include:
- 服务已经崩溃或尚未开始,
- 您的客户尝试使用了错误的IP地址或端口,连接或
- 服务器的访问被防火墙阻止那就是拒绝接受代服务器/服务的。这是pretty不太可能,因为正常的做法(这几天)是防火墙黑洞的所有不必要的连接尝试。
这篇关于java.net.ConnectException:无法连接到/192.168.253.3(端口2468):连接失败:ECONNREFUSED(连接被拒绝)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!