0

In any iteration within the while, a SocketException: Connection reset is generated. can someone give me some suggestions?

    logger.info("Start send xml");
    StringBuilder bld = new StringBuilder();

    try (Socket socket = new Socket(ipAddress,port)){

        socket.setSoTimeout(600000);
        OutputStream output = socket.getOutputStream();
        PrintWriter writer = new PrintWriter(output, true);
        writer.println(xml);
        writer.flush();

        InputStream input = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(input));
        String line;

        while ((line = reader.readLine()) != null)
            bld.append(line);


        writer.close();
        reader.close();
    } catch (IOException e) {
        logger.error("Error sending the XML");
        logger.error(e.getMessage());
        throw new SendXMLException(e.getMessage());
    }

    logger.info("End Send xml -> " + bld.toString());
    return bld.toString();
Alessandro
  • 31
  • 5
  • That usually means a network problem. Double check that `ipAddress`:`port` is actually listening. You can verify with a tool like telnet: `telnet ` – dontocsata Feb 21 '19 at 16:16
  • Several reasons a `SocketException.class` is thrown [Socket Exception SE 8](https://docs.oracle.com/javase/8/docs/api/java/net/SocketException.html). "error creating or accessing a Socket." Which Java Version are you using? – Mr00Anderson Feb 21 '19 at 16:17
  • Also it helps to have the whole set of code in a working manner. More likely to get a good response when a person can easily take your code and paste it to run it. – Mr00Anderson Feb 21 '19 at 16:23
  • Take a look here for examples of some newer java ways Java 7 using NIO. [Java Code Geeks](https://examples.javacodegeeks.com/core-java/nio/java-nio-large-file-transfer-tutorial/) – Mr00Anderson Feb 21 '19 at 16:34
  • Server closes your connection. – Some Name Feb 21 '19 at 17:51
  • @dontocsatathe server is always active @ Mr00Anderson Java 8 – Alessandro Feb 22 '19 at 08:02

0 Answers0