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

猜你喜欢

转载自www.cnblogs.com/chenfx/p/13384667.html
今日推荐