NIO client giving exception : java.net.ConnectException: Connection refused: no further information

后端 未结 3 742
生来不讨喜
生来不讨喜 2020-12-18 04:27

I modified the sample code available here for Client and Server My client :

public class Client {

public static void main(String[] args) {

    int n=10000;         


        
3条回答
  •  伪装坚强ぢ
    2020-12-18 05:07

    I believe the ConnectException you are getting with 500 threads is not coming from SocketTest.connect(). It could be coming from any of the other IO methods.

    For a quick fix (and to convince yourself), you can explicitly catch ConnectException in your main try-catch block like this:

    try {
        // connect, write, and read ...
    } catch (ConnectException ce) {  // <-- catch the more specific Exception first
        System.out.println("You caught a ConnectException.");
    } catch (IOException e1) {       // <-- you originally only caught this
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } finally {
    

    As to why this is happening, I can tell you that I am currently ramping up to hundreds of threads for testing a SOAP service. I also get dropped connections all over the place, so maybe this is to be expected with such a large number of concurrent threads.

提交回复
热议问题