Java sockets - java.net.ConnectException: Connecti

2020-03-31 20:14发布

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/ 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.

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

2条回答
家丑人穷心不美
2楼-- · 2020-03-31 20:30

Have a look at the answers to: java.net.ConnectException: Connection refused

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

查看更多
一纸荒年 Trace。
3楼-- · 2020-03-31 20:33

Is your client on same LAN as your server? I think you should re-check IP address / host name and port number to which your client is connecting.

查看更多
登录 后发表回答