简体   繁体   English

Java套接字 - java.net.ConnectException:连接被拒绝:连接

[英]Java sockets - java.net.ConnectException: Connection refused: connect

I've created a simple chat program which communicates using sockets. 我创建了一个简单的聊天程序,它使用套接字进行通信。 Everything works fine when I'm running it on localhost. 当我在localhost上运行时,一切正常。 However, the problems occur when I try to link the client and server programs using my IP. 但是,当我尝试使用我的IP链接客户端和服务器程序时,会出现问题。

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 . http://www.canyouseeme.org/可以通过端口9999连接到我的服务器,所以我知道服务器很好,端口是打开的 However, my client can't connect. 但是,我的客户端无法连接。

The error log... 错误日志......

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. 提前致谢。

Edit: Links to the full source code: 编辑:完整源代码的链接:

http://pastebin.com/2XftHtn9 http://pastebin.com/2XftHtn9

Have a look at the answers to: java.net.ConnectException: Connection refused 看看答案: java.net.ConnectException:连接被拒绝

My first suspicion however would be a firewall issue..... 然而,我的第一个怀疑是防火墙问题......

Is your client on same LAN as your server? 您的客户端是否与服务器位于同一LAN上? I think you should re-check IP address / host name and port number to which your client is connecting. 我认为您应该重新检查客户端连接的IP地址/主机名和端口号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java Mail错误:java.net.ConnectException:连接被拒绝:connect - Java Mail Error : java.net.ConnectException: Connection refused: connect Java网络问题:java.net.ConnectException:连接被拒绝:连接 - Java Networking Problem: java.net.ConnectException: Connection refused: connect Java 中的 ssh 异常:java.net.ConnectException:连接被拒绝:连接 - ssh Exception in Java: java.net.ConnectException: Connection refused: connect java.net.ConnectException:连接被拒绝:connect java nio - java.net.ConnectException: Connection refused: connect java nio Java java.net.ConnectException:连接被拒绝 - Java java.net.ConnectException: Connection refused java.net.ConnectException:连接被拒绝:connect openshift - java.net.ConnectException: Connection refused: connect openshift java.net.ConnectException:拒绝连接:连接HTTPS连接 - java.net.ConnectException: Connection refused: connect for HTTPS connections 获取java.net.ConnectException:连接被拒绝:在Eclipse中连接 - Getting java.net.ConnectException: Connection refused: connect in eclipse RMI(java.net.ConnectException:连接被拒绝:连接) - RMI(java.net.ConnectException: Connection refused: connect) java.net.ConnectException:连接被拒绝:用 Spring boot 连接 Solr - java.net.ConnectException: Connection refused: connect Solr with Spring boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM