Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to solve the problem of JAVA.NET.SOCKETEXCEPTION: SOFTWARE CAUSED CONNECTION ABORT: RECV FAILED

Shulou Source: shulou.com Published: 2022-06-02 08:13:06 09月21日 Update

This article mainly explains "error reporting JAVA.NET.SOCKETEXCEPTION: SOFTWARE CAUSED CONNECTION ABORT: RECV FAILED how to solve", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "error reporting JAVA.NET.SOCKETEXCEPTION: SOFTWARE CAUSED CONNECTION ABORT: RECV FAILED how to solve" it!

There are many reasons for this exception, as shown in Software caused alone.

It is caused by programming problems, not network problems.

A scenario that is known to cause this exception is as follows:

The client and the server establish a short connection to tcp, and the client sends a request each time

The server closes the connection with the client after responding.

If the client does not release the connection after the server closes the connection, it continues to try to send the request and receive the response.

Things will go wrong at this time.

The OutPutStream maintenance returned by the getOutputStream of the client Socket at this time

Is the local connection status

It is impossible to know that the remote server has shut down the corresponding InputStream and socket, so

Although it called the

Out.write (sendbuf, 0, sendbuf.length)

Method, but in fact, the server does not receive the request information from the client.

Because no exception is thrown, it creates a false impression that the client request was sent successfully.

Next, call the in.read (header, 0,14); method of etInputStream.

Because this time we have to read the information from the server, it produces

Software caused connection abort: exception of recv failed

To sum up the cause, when the server / client unilaterally closes the connection, the other party still thinks

The tcp connection is still established, trying to read the other party's response data, resulting in

Software caused connection abort: the exception of recv failed.

Therefore, before receive data, it is necessary to determine the connection status.

Whether there is a response result is judged by the available () method of inputstream.

If the return value of available () is 0, there is no response data, and the other party may have been disconnected

If the return value of available () is greater than 0, there is response data.

It is also worth noting that the value returned by available () is non-blocking and can be accessed by multiple threads.

After the other party releases the connection, also release the local connection

Thank you for your reading, the above is the content of "error reporting JAVA.NET.SOCKETEXCEPTION: SOFTWARE CAUSED CONNECTION ABORT: RECV FAILED how to solve". After the study of this article, I believe you have a deeper understanding of how to report error JAVA.NET.SOCKETEXCEPTION: SOFTWARE CAUSED CONNECTION ABORT: RECV FAILED to solve this problem, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Customer service client data other party method end problem learning information content reason situation time status success next one side illusion unilateral Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Shulou Information Docker Shulou Technology MariaDB