我们java.net.SocketException: Connection reset
在日志中看到频繁但间歇性的 错误.我们不确定Connection reset
错误实际来自何处,以及如何进行调试.
该问题似乎与我们尝试发送的邮件无关.请注意,消息不是 connection reset by peer
.
有关此异常的典型原因可能是什么的建议,以及我们如何进行?
这是一个代表性的堆栈跟踪(com.companyname.mtix.sms
是我们的组件):
java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:168) at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) at java.io.BufferedInputStream.read(BufferedInputStream.java:235) at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:77) at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:105) at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1115) at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1832) at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1590) at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:995) at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:397) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:170) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:396) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:324) at com.companyname.mtix.sms.services.impl.message.SendTextMessage.sendTextMessage(SendTextMessage.java:127) at com.companyname.mtix.sms.services.MessageServiceImpl.sendTextMessage(MessageServiceImpl.java:125) at com.companyname.mtix.sms.services.remote.MessageServiceRemoteImpl.sendTextMessage(MessageServiceRemoteImpl.java:43) at sun.reflect.GeneratedMethodAccessor203.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:453) at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) …
我无法找到适当的答案,以确定以下错误的含义:
java.net.SocketException: Software caused connection abort: recv failed
笔记:
相关代码:
BufferedReader reader;
try {
URL url = new URL(URI);
reader = new BufferedReader(new InputStreamReader(url.openStream())));
} catch( MalformedURLException e ) {
throw new IOException("Expecting a well-formed URL: " + e);
}//end try: Have a stream
String buffer;
StringBuilder result = new StringBuilder();
while( null != (buffer = reader.readLine()) ) {
result.append(buffer);
}//end while: Got the contents.
reader.close();
Run Code Online (Sandbox Code Playgroud) 当我从服务器读取文件内容时,它返回以下错误消息:
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
Run Code Online (Sandbox Code Playgroud)
我的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();
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
我正在尝试将图像从Java桌面应用程序发送到J2ME应用程序.问题是我得到了这个例外:
java.net.SocketException: Software caused connection abort: socket write error
Run Code Online (Sandbox Code Playgroud)
我在网上四处看看,尽管这个问题并不罕见,但我无法找到具体的解决方案.我在传输之前将图像转换为字节数组.这些是分别在桌面应用程序和J2ME上找到的方法
public void send(String ID, byte[] serverMessage) throws Exception
{
//Get the IP and Port of the person to which the message is to be sent.
String[] connectionDetails = this.userDetails.get(ID).split(",");
Socket sock = new Socket(InetAddress.getByName(connectionDetails[0]), Integer.parseInt(connectionDetails[1]));
OutputStream os = sock.getOutputStream();
for (int i = 0; i < serverMessage.length; i++)
{
os.write((int) serverMessage[i]);
}
os.flush();
os.close();
sock.close();
}
private void read(final StreamConnection slaveSock)
{
Runnable runnable = new Runnable()
{
public void …
Run Code Online (Sandbox Code Playgroud) 可能重复:
"软件导致连接中止:套接字写入错误"的官方原因
我有蓝牙问题我无法连接Droid.我总是得到这个IOException
08-09 20:58:24.889: INFO/BluetoothChat(17378): MESSAGE_STATE_CHANGE: 3
08-09 20:58:51.053: DEBUG/BluetoothService(17378): BT_SEND_MESSAGE
08-09 20:58:51.108: ERROR/BluetoothService(17378): disconnected
08-09 20:58:51.108: ERROR/BluetoothService(17378): java.io.IOException: Software caused connection abort
08-09 20:58:51.108: ERROR/BluetoothService(17378): at android.bluetooth.BluetoothSocket.readNative (Native Method)
08-09 20:58:51.108: ERROR/BluetoothService(17378): at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:286)
08-09 20:58:51.108: ERROR/BluetoothService(17378): at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
08-09 20:58:51.108: ERROR/BluetoothService(17378): at java.io.InputStream.read(InputStream.java:133)
08-09 20:58:51.108: ERROR/BluetoothService(17378): at my.test.BluetoothChatService$ConnectedThread.run(BluetoothChatService.java:356)
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
我试图中止套接字连接,以便另一端的客户端将获得"WSAECONNABORTED(10053)软件导致连接中止".轮询连接时出现错误消息.
Close()和Shutdown()将正常断开连接.我不想要一个优雅的断开连接.我想做一次Abort,以便客户感觉到出了什么问题.
谢谢,
编辑:我正在编写服务器编码,我想中止套接字连接客户端
所有。我已经遇到了几天的问题,这是详细信息堆栈信息:
org.springframework.dao.RecoverableDataAccessException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 18,940 milliseconds ago. The last packet sent successfully to the server was 18,918 milliseconds ago.
### The error may involve com.tuan800.searchtask.model.dao.mybatis.RelationDao.updateSuggest-Inline
### The error occurred while setting parameters
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 18,940 milliseconds ago. The last packet sent successfully to the server was 18,918 milliseconds ago.
; SQL …
Run Code Online (Sandbox Code Playgroud) 我想忽略/静音的例外如下:
Resolved exception caused by handler execution: org.apache.catalina.connector.ClientAbortException: java.net.SocketException: Software caused connection abort: socket write error
并且仅在我使用 Firefox 访问应用程序时引起。
欢迎任何想法。
在@CodeRider 的回答之后,我编辑了我的异常处理程序并使用了以下条件 if(exception instanceof ClientAbortException && response.isCommitted()){return null;}
当我处于调试模式时,我可以看到我确实返回了 null 而不是 super.doResolveException()。
但是,我仍然可以在控制台中看到该异常。这是完整的堆栈跟踪:
Dec 02, 2019 5:48:20 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [spring-mvc] in context with path [/xxxxxx] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed] with root cause
java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been …
Run Code Online (Sandbox Code Playgroud) 我在Netbeans IDE中的Java,Hibernate,MySQL项目中遇到异常.
我已经做了一些挖掘尝试修复这个奇怪的Socket异常,但无济于事.
一些论坛解决方案建议为Hibernate实现一个c3p0连接池.没有问题.
其他人建议禁用AV和防火墙(!!),因为这些可能会干扰套接字连接.没有问题.
我用Hibernate标记了这个问题,因为我不确定hibernate是什么原因,但Hibernate调用(运行查询)会出现异常.应用程序中的其他Hibernate代码工作正常.Hibernate版本是3.2.
例外:
NotifyUtil::java.net.SocketException: Software caused connection abort: recv failed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2676)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at org.netbeans.modules.web.monitor.server.NotifyUtil$RecordSender.run(NotifyUtil.java:299)
Run Code Online (Sandbox Code Playgroud)
此异常可能发生一次或几次,并且之后不会出现此异常:
NotifyUtil::java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at java.io.FilterInputStream.read(FilterInputStream.java:116)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:2676)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at java.io.BufferedReader.fill(BufferedReader.java:136)
at java.io.BufferedReader.readLine(BufferedReader.java:299)
at java.io.BufferedReader.readLine(BufferedReader.java:362)
at org.netbeans.modules.web.monitor.server.NotifyUtil$RecordSender.run(NotifyUtil.java:299)
Run Code Online (Sandbox Code Playgroud)
非常感谢帮助.这有点奇怪.
谢谢.
这基本上是图片:我有一个服务器和一个客户端(通过localhost操作).服务器为每个连接创建一个客户端线程.这个新线程在读取等待来自客户端的消息时阻塞.随意,我可以通过GUI停用服务器,GUI将(从主线程)"断开"发送到客户端,然后关闭输出流,唤醒被阻止的客户端线程,然后通过关闭套接字完成(我认为在关闭输出流之后这种关闭是不必要的,但无论如何).
客户端:连接请求后,它会休眠10秒,写入断开连接消息并通过char读取答案字符.
问题:
在该10秒客户端休眠时间内停用服务器后,客户端从服务器正确读取"断开连接"消息.但是,如果我只为每个char读取添加一个虚拟打印(在while循环内),则最终读取的结果会发生变化.有时它会正确读取服务器的"断开连接",有时会读取"disco"或类似的变体,并抛出此异常:
"Java异常:"软件导致连接中止:recv失败"
有关添加少量打印件的原因有何建议可以创建此结果?我会假设另一端有一个封闭的套接字对读取消息没有影响.我发现有关recv错误的其他线程提到超时,我猜测在使用localhost时应该不会发生这种情况?
我正在TCP上创建一个java客户端/服务器应用程序,我们有两个套接字:
我在Server中创建了两个ServerSockets,以便
通过接受ServerSockets 来创建Socket One和Two
.
首先,客户端通过第一个Socket发送一些字节,
以便它可以告诉服务器它需要哪个文件.
然后服务器通过第二个套接字将文件发送到客户端.
客户端收到文件后,尝试向服务器发送一个Transfer Done Message.
在那里,我得到了关闭套接字的异常.
但是我直到现在才关闭套接字.
我只关闭发送文件的缓冲区.
即使我在发送文件后尝试再次打开socketInputStream,错误仍然是相同的.
此外,如果我不关闭发送文件的缓冲区,客户端将不会获取该文件.
服务器异常
返回消息中的错误 - java.net.SocketException:socket已关闭
客户端例外
服务器响应 - java.net.SocketException:软件导致连接中止:套接字写入错误
我究竟做错了什么?