gpt4 book ai didi

java - 如何解决 "Connection reset by peer: socket write error"?

转载 作者:IT老高 更新时间:2023-10-28 20:54:14 25 4
gpt4 key购买 nike

当我从服务器读取文件内容时,它返回以下错误消息:

Caused by: java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:215)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:462)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:366)
at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:240)
at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:119)
at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
at org.apache.coyote.Response.doWrite(Response.java:504)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:383)
... 28 more

我的 servlet 程序是

 response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename="+filename);
FileInputStream in = new FileInputStream(new File(filepath));
ServletOutputStream output=response.getOutputStream();
byte[] outputByte=new byte[4096];
while(in.read(outputByte,0,4096)!=-1){
output.write(outputByte,0,4096);//error indicates in this line
}
in.close();
output.flush();
output.close();

如何解决这个问题?

最佳答案

我遇到了同样的异常(exception)情况,在我的情况下,问题出在重新谈判过程中。事实上,当服务器尝试更改密码套件时,我的客户端关闭了连接。挖掘后看来,在 jdk 1.6 更新 22 renegotiation process is disabled by default .如果您的安全限制可以解决此问题,请尝试通过将 sun.security.ssl.allowUnsafeRenegotiation 系统属性设置为 true 来启用不安全的重新协商。以下是有关该过程的一些信息:

Session renegotiation is a mechanism within the SSL protocol that allows the client or the server to trigger a new SSL handshake during an ongoing SSL communication. Renegotiation was initially designed as a mechanism to increase the security of an ongoing SSL channel, by triggering the renewal of the crypto keys used to secure that channel. However, this security measure isn't needed with modern cryptographic algorithms. Additionally, renegotiation can be used by a server to request a client certificate (in order to perform client authentication) when the client tries to access specific, protected resources on the server.

另外还有 excellent post关于这个问题的详细信息并用(恕我直言)可理解的语言编写。

关于java - 如何解决 "Connection reset by peer: socket write error"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12986542/

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