连接在远程IP上被拒绝,但在本地IP上被接受 [英] Connection refused on remote IP, but accepted on local IP

查看:150
本文介绍了连接在远程IP上被拒绝,但在本地IP上被接受的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我让我的服务器在本地机器上运行,我测试并调试它并且它工作得很好(服务器也用java编写)。但当我尝试使用我的远程IP(而不是192.168.0.113,我使用146.255.xx)测试它,并且服务器没有收到任何东西,而客户端抛出了这个:

As the title says, I have my server running on a local machine, I tested and debugged it and it worked perfectly (server is written in java as well). But when I tried to test it with my remote IP (instead of 192.168.0.113 I used 146.255.x.x), and the server didn't receive anything, while the client has thrown this:

09-04 18:23:27.595: W/System.err(24241): java.net.ConnectException: failed to connect to /146.255.x.x (port 4040): connect failed: ECONNREFUSED (Connection refused)
09-04 18:23:27.595: W/System.err(24241):    at libcore.io.IoBridge.connect(IoBridge.java:114)
09-04 18:23:27.595: W/System.err(24241):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
09-04 18:23:27.595: W/System.err(24241):    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
09-04 18:23:27.595: W/System.err(24241):    at java.net.Socket.startupSocket(Socket.java:566)
09-04 18:23:27.595: W/System.err(24241):    at java.net.Socket.tryAllAddresses(Socket.java:127)
09-04 18:23:27.595: W/System.err(24241):    at java.net.Socket.<init>(Socket.java:177)
09-04 18:23:27.595: W/System.err(24241):    at java.net.Socket.<init>(Socket.java:149)
09-04 18:23:27.595: W/System.err(24241):    at com.statenislandchat.Main$2$1$1.run(Main.java:146)
09-04 18:23:27.595: W/System.err(24241): Caused by: libcore.io.ErrnoException: connect failed: ECONNREFUSED (Connection refused)
09-04 18:23:27.595: W/System.err(24241):    at libcore.io.Posix.connect(Native Method)
09-04 18:23:27.600: W/System.err(24241):    at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85)
09-04 18:23:27.600: W/System.err(24241):    at libcore.io.IoBridge.connectErrno(IoBridge.java:127)
09-04 18:23:27.600: W/System.err(24241):    at libcore.io.IoBridge.connect(IoBridge.java:112)
09-04 18:23:27.600: W/System.err(24241):    ... 7 more

我很久以前在服务器PC上禁用了防火墙,我在路由器上转发了端口。我尝试了一些portscanners,他们都检测到我的端口上的服务,但我的客户端无法一次又一次地到达它。

I disabled the firewall on the server PC long ago, and I DID forward the ports on my router. I tried with some portscanners and they all detect a service on my port, but my client fails to reach it again and again.

已解决!
我对网络的关注不多,但如果服务器和客户端都在同一台路由器上,似乎无法像这样连接。我尝试从远程客户端连接并且它有效。

SOLVED! I'm not much into networking but it seems that its impossible to connect like this if both the server and client are on the same router. I tried connecting from a distant client and it worked.

推荐答案

ECONNREFUSED表示尝试连接,远程主机回答没人在监听该端口。这可能意味着几件事:

ECONNREFUSED means that the connection was attempted and the remote host answered back that nobody's listening on that port. That could mean several things:


  1. 这真的是你的IP吗? ifconfig / ipconfig说什么(提示:不一定是什么whatismyip.com会说)?

  2. Java服务器是否监听所有接口?同一端口可以在localhost上打开,在其他接口上关闭。检查服务器上的绑定地址。

  3. 尝试使用telnet + tcpdump,是否显示数据包到达正确的地址?

这些只是一个开始。

这篇关于连接在远程IP上被拒绝,但在本地IP上被接受的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆