Resolution 1:
Software caused connection Abort:recv failed
Java.net.SocketException:Software caused connection Abort:recv failed
At java.net.SocketInputStream.socketRead0 (Native Method)
At Java.net.SocketInputStream.read (socketinputstream.java:129)
There are several reasons for this exception, as shown in software caused,
is due to a problem with the program writing, not the network problem.
One scenario that is known to cause this exception is as follows:
The client and the server make a short connection to TCP, and each time the client sends a request, the server closes the connection to the client after the service side responds. If the client closes the connection on the server, it does not release the connection and continues to attempt to send the request and receive the response. This time it will be wrong .
This time the client socket Getoutputstream returned to the OutputStream to maintain the local connection state, do not know that the remote server has closed the corresponding inputstream and socket so that although the call Out.write ( SendBuf, 0, sendbuf.length); method, but actually the server does not receive the client's request information. Because there is no exception thrown, it creates the illusion that the client request was successfully sent.
Next Call Etinputstream's In.read (header, 0, 14); Because this time to read the server information, resulting in software caused connection Abort:recv failed exception
Summary of the cause, in the case of the service side/client unilaterally shut down the connection, the other side still think the TCP connection is still established, trying to read the response data of the other, resulting in software caused connection Abort:recv failed exception.
Therefore, before you receive data, you must first determine the connection status. The InputStream available () method is used to determine whether there is a response result. If the return value of available () is 0, there is no response data, it is possible that the other party has disconnected, and if the return value of available () is greater than 0, the response data is indicated. It is also worth noting that the value returned by available () is non-clogging and can be accessed by multiple threads
After the other party releases the connection, it also releases the local connection.
Original code: URL localurl =NewURL (URL); URLConnection UC =Localurl.openconnection (); Uc.setrequestproperty ("User-agent", "mozilla/3.5.7" (compatible; MSIE 5.0; Windows NT; Digext) "); Uc.connect (); InputStream LocalObject1 =Localurl.openstream (); System.out.println (Localobject1.available ());byte[] LocalObject2 =Newbyte[131072]; StringBuffer Localstringbuffer =NewStringBuffer ();Int j = 0;while ((j = (LocalObject1). Read (LOCALOBJECT2)) > 0) {Localstringbuffer.append (New String (LOCALOBJECT2, 0, J, encoder)); } localobject1.close (); Modified code: URL Localurl =NewURL (URL); URLConnection UC =Localurl.openconnection (); Uc.setrequestproperty ("User-agent", "mozilla/3.5.7" (compatible; MSIE 5.0; Windows NT; Digext) "); Uc.connect (); InputStream LocalObject1 =Localurl.openstream (); System.out.println (Localobject1.available ());byte[] LocalObject2 =Newbyte[131072]; StringBuffer Localstringbuffer =NewStringBuffer ();Int j = 0;while (trueif (LocalObject1 available () >0) {if (y= Localobject1.read (LOCALOBJECT2)) >0,y,encode)); } else{break ; }}else if (In.available () ==0 break
Resolution 2:
When the socket is connected, as soon as I read the data, that is, Read,catch immediately get an exception message
"Software caused connection Abort:recv failed"
After the argument, it turned out that I transmitted data and Monitoring Center Server Protocol Data inconsistent, no login success, so I can not accept the data
I'm not using the NIO package, and I'm starting to suspect that any one of these java.net.SocketException exceptions could be the result of inconsistent protocol data.
As follows: Four kinds of error messages
Java.net.SocketException:Connection Reset by Peer:socket write error java.net.SocketException:Connection Reset Java.net.SocketException:Software caused connection Abort:socket write error
Java.net.SocketException:Software caused connection Abort:recv failed
Software caused connection Abort:recv failed error description