隐藏

Exception in thread "main" java.net.ConnectException: Connection refused: connect

发布:2021/8/4 8:17:34作者:管理员 来源:本站 浏览次数:942

客户端连接异常:

复制代码
Exception in thread "main" java.net.ConnectException: Connection refused: connect
    at sun.nio.ch.Net.connect0(Native Method)
    at sun.nio.ch.Net.connect(Net.java:454)
    at sun.nio.ch.Net.connect(Net.java:446)
    at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
    at homework.test5.client.main(client.java:16)
复制代码

原因:

1、server服务器未开启,客户端与服务器的设置端口不一致;

2、也可能是server运行后,ServerSocker.close()、ServerSocketChannel.close()、synchronousServerSocketChannel.close()。所以服务器在客户端连接之前不能关闭,或者就不关闭服务器。