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

 

客户端连接异常:

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()。所以服务器在客户端连接之前不能关闭,或者就不关闭服务器。

posted @ 2020-07-27 11:51  炼金术士0z  阅读(9598)  评论(0编辑  收藏  举报