Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch the IOException "Connection reset by peer"?

Parsing the string message seems bad. Or was this exception not meant to be caught?

java.io.IOException: Connection reset by peer
    at sun.nio.ch.FileDispatcher.read0(Native Method)
    at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:21)
like image 378
chrisapotek Avatar asked Mar 22 '12 19:03

chrisapotek


People also ask

What does Java IOException Connection reset by peer mean?

io. IOException: Connection reset by peer are given below. If the other side has abruptly aborted the connection in the middle of a transaction that is not controllable from the server-side. If the end-user decides to shutdown the client or changes the server abruptly when that server interacts with your server.

What is Connection reset by peer?

Connection Reset by peer means the remote side is terminating the session. This error is generated when the OS receives notification of TCP Reset (RST) from the remote server.

How do I resolve IOException?

In order to fix it, you would want to see the stack trace of your exception or at least the message, to see exactly where the exception is thrown and why. try { methodThrowingIOException(); } catch (IOException e) { System. out. println(e.

Can firewall cause Connection reset by peer?

The error message "Connection reset by peer" appears, if the web services client was waiting for a SOAP response from the remote web services provider and the connection was closed prematurely. One of the most common causes for this error is a firewall in the middle closing the connection.


1 Answers

You need to catch the IOException and, yes, parse the string.

There isn't any other exception more specific than that to be caught as far as I know.

Or catch SocketException and, again, parse the string.

Here's the class tree from javadoc (version 6). As you can see, SocketException is the most specialized exception to be thrown when the connection is reset.

like image 133
lucian.pantelimon Avatar answered Sep 22 '22 02:09

lucian.pantelimon