Java套接字 - java.net.ConnectException:连接被拒绝:连接 [英] Java sockets - java.net.ConnectException: Connection refused: connect

查看:305
本文介绍了Java套接字 - java.net.ConnectException:连接被拒绝:连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的聊天程序,它使用套接字进行通信。当我在localhost上运行时,一切正常。但是,当我尝试使用我的IP链接客户端和服务器程序时会出现问题。

I've created a simple chat program which communicates using sockets. Everything works fine when I'm running it on localhost. However, the problems occur when I try to link the client and server programs using my IP.

http://www.canyouseeme.org/ 可以通过端口9999连接到我的服务器,所以我知道服务器正常,端口已打开。但是,我的客户端无法连接。

http://www.canyouseeme.org/ can connect to my server on port 9999 so I know that the server is fine and the port is open. However, my client can't connect.

错误日志...

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at Client.connect(Client.java:129)
at Client.main(Client.java:47)

有人知道可能导致这种情况的原因吗?提前致谢。

Does anybody have any idea what might be causing this? Thanks in advance.

修改:
链接到完整的源代码:

Links to the full source code:

http://pastebin.com/2XftHtn9

推荐答案

查看以下答案: java .net.ConnectException:连接被拒绝

我的第一个怀疑是防火墙问题......

My first suspicion however would be a firewall issue.....

这篇关于Java套接字 - java.net.ConnectException:连接被拒绝:连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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