gpt4 book ai didi

java - 异常 java.net.SocketException : Connection reset

转载 作者:行者123 更新时间:2023-12-02 12:32:39 27 4
gpt4 key购买 nike

我编写了一段代码来解析来自代理服务器的 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)

当我在该服务器上执行 ping 操作时,在某些情况下会遇到“请求超时”的情况。这是服务器配置问题、网络问题还是编码问题?

我的代码:

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

}

最佳答案

如果您正在 ping 服务器并收到请求超时,则意味着您正在 ping 的任何内容都没有收到您的 ping。此外,由于错误消息指出连接已重置,这可能表明服务器失去了与您的应用程序的连接。简而言之,与服务器的连接已建立,但是当您开始与服务器通信时,它会重置连接。

对此持保留态度,因为您提供的代码似乎不是处理套接字本身的原始代码,所以我不能代表代码发言。

Tldr;服务器超时,因此连接正在重置。也可能是实际处理套接字的代码

关于java - 异常 java.net.SocketException : Connection reset,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45217263/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com