是什么导致我的SocketException:连接重置?

时间:2019-02-21 16:12:40

标签: java sockets connection socketexception connection-reset

在while内的任何迭代中,都会产生SocketException:连接重置。有人可以给我一些建议吗?

    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();

0 个答案:

没有答案