简体   繁体   English

异常java.net.SocketException:连接重置

[英]Exception java.net.SocketException: Connection reset

I have written a code to parse a csv file from a proxy server.But after a specific time interval (after parsing some csv lines), it is giving this error: 我写了一段代码来从代理服务器解析一个csv文件,但是经过一个特定的时间间隔(解析了一些csv行之后),它给出了这个错误:

DEBUG [csvFile-267] Successfully parsed usage CSV file for 30 rows
ERROR  [csvFile-271] Exception occurred in csvFile() 
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)  

When I am pinging on that server I am getting "request timeout" in some cases. 在该服务器上ping时,在某些情况下会出现“请求超时”。 Is that a server configuration problem, or network, or coding? 这是服务器配置问题,还是网络或编码?

My Code: 我的代码:

    while ((line = reader.readLine()) != null) {
            UsageResponse usageResponse = new UsageResponse();
            ErrorDetails errorDetails = new ErrorDetails();
            try {
                //fileData = line.split(splitby);
                fileData = line.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)");

                if (isheaderReadable) {

                    for (int headerCounter = 0; headerCounter < fileData.length; headerCounter++) {
                        if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_START_DATE)) {
                            usageStartDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_REPORT_END_DATE)) {
                            usageEndDateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ACCOUNT_ID)) {
                            linkedAccountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_CODE)) {
                            productCodeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_TYPE)) {
                            usageTypeLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_USAGE_AMOUNT)) {
                            usageAmountLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_RATE)) {
                            unBlendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_UNBLENDED_COST)) {
                            unBlendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_RATE)) {
                            blendedrateLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_BLENDED_COST)) {
                            blendedCostLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_ITEM_DESCRIPTION)) {
                            lineItemDescriptionLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_LOCATION)) {
                            productLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_SKU)) {
                            productSKULocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_NAME)) {
                            productNameLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_PRODUCT_GROUP)) {
                            productGroupLocation = headerCounter;
                        } else if (fileData[headerCounter].equalsIgnoreCase(Constants.DAILY_USAGE_LINE_ITEM_TYPE)) {
                            lineTypeLocation = headerCounter;
                        }
                    }
                    isheaderReadable = false;
                } else {

                    if (!fileData[lineTypeLocation].equalsIgnoreCase("Tax") && !fileData[lineTypeLocation].equalsIgnoreCase("DiscountedUsage")) {
                        usageResponse.setProductCode(fileData[productCodeLocation]);
                        usageResponse.setUsageStartDate(fileData[usageStartDateLocation]);
                        usageResponse.setUsageEndDate(fileData[usageEndDateLocation]);

                        if (fileData[blendedCostLocation] != null && !fileData[blendedCostLocation].isEmpty()) {
                            usageResponse.setBlendedCost(Double.parseDouble(fileData[blendedCostLocation]));
                        }
                        if (fileData[unBlendedCostLocation] != null && !fileData[unBlendedCostLocation].isEmpty()) {
                            usageResponse.setUnblendedCost((Double.parseDouble(fileData[unBlendedCostLocation])));
                        }
                        if (fileData[blendedrateLocation] != null && !fileData[blendedrateLocation].isEmpty()) {
                            usageResponse.setBlendedRate(Double.parseDouble(fileData[blendedrateLocation]));
                        }
                        if (fileData[unBlendedrateLocation] != null && !fileData[unBlendedrateLocation].isEmpty()) {
                            usageResponse.setUnblendedRate((Double.parseDouble(fileData[unBlendedrateLocation])));
                        }

                        usageResponse.setItemDescription(fileData[lineItemDescriptionLocation]);

                        if (fileData[usageAmountLocation] != null && !fileData[usageAmountLocation].isEmpty()) {
                            usageResponse.setUsageAmount(Double.parseDouble(fileData[usageAmountLocation]));
                        }
                        usageResponse.setUsageType(fileData[usageTypeLocation]);
                        usageResponse.setLocation(fileData[productLocation]);
                        usageResponse.setLinkedAccountId(fileData[linkedAccountLocation]);
                        usageResponse.setProductSKU(fileData[productSKULocation]);
                        usageResponse.setProductName(fileData[productNameLocation]);
                        usageResponse.setProductGroup(fileData[productGroupLocation]);
                        usageResponseList.add(usageResponse);
                    }
                }
            } catch (AWSCostAndUsageReportException e) {
                logger.error("Error is occurred during retrieving usage amounts ", e);
                errorDetails.setCode(e.getErrorCode());
                errorDetails.setMessage(e.getMessage());
                usageResponse.setErrorDetails(errorDetails);
            }
            listUsage.setUsageResponses(usageResponseList);

        }

If you are pinging the server and getting a request time out that means that what ever you are pinging is not receiving your ping. 如果您对服务器执行ping操作并导致请求超时,则意味着您所执行的ping操作均未收到您的ping命令。 Also, since the error message states that the Connection has reset that could be indicative of the server loosing connection to your application. 同样,由于错误消息指出连接已重置,这可能表明服务器失去了与应用程序的连接。 In short, the connection to the server is made, but when you start to talk to the server it resets the connection. 简而言之,已建立与服务器的连接,但是当您开始与服务器对话时,它将重置连接。

Take that with a grain of salt because the code you have supplied does not seem to be the raw code that is handling the socket itself, so I cannot speak on the behalf of the code. 有点麻烦,因为您提供的代码似乎不是处理套接字本身的原始代码,所以我不能代表该代码发言。

Tldr; Tldr; Server is timing out so the connection is resetting. 服务器超时,因此连接正在重置。 Could also be the code actually handling the socket 也可能是实际处理套接字的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM