What's Causing My Java.Net.Socketexception: Connection Reset

What's causing my java.net.SocketException: Connection reset?

The javadoc for SocketException states that it is

Thrown to indicate that there is an error in the underlying protocol such as a TCP error

In your case it seems that the connection has been closed by the server end of the connection. This could be an issue with the request you are sending or an issue at their end.

To aid debugging you could look at using a tool such as Wireshark to view the actual network packets. Also, is there an alternative client to your Java code that you could use to test the web service? If this was successful it could indicate a bug in the Java code.

As you are using Commons HTTP Client have a look at the Common HTTP Client Logging Guide. This will tell you how to log the request at the HTTP level.

Why do I keep getting a java.net.SocketException: Connection reset error?

I had a colleague who ran into an issue like this.

He found out that it was because the server he was calling had removed support for TLS 1.0 but java 7 was defaulting to use TLS 1.0.

He fixed it by forcing java to use TLS 1.2.

java -Dhttps.protocols=TLSv1.2 GetURL https://artifactory.somewhere.com/artifactory/webapp

Getting java.net.SocketException Connection reset error in socket communication with threads

java.net.SocketException: Connection reset

This means the OS has reseted the connection because the process on the other end is no longer running. It looks like your client crashes after processing first reply from the server.

Scanner scanner = new Scanner(System.in);
scanner.close();

Do not close Scanners operating on System.in. This will close System.in and you will not be able to read anything anymore from there.

What's causing java.net.SocketException: Connection reset after closing client?

You are correct. You have to close the client socket properly before exiting the client. Otherwise the operating system may reset the connection instead of closing it. Not being an Android guy I cannot advise you where this closure should be placed.

Your server has a problem too. It needs to catch EOFException in the read loop and silently break. At present you aren't handling end of stream correctly: you will catch it via catch (EOFException ) and log it as an error, which it isn't really.

Exception java.net.SocketException: Connection reset

If you are pinging the server and getting a request time out that means that what ever you are pinging is not receiving your ping. Also, since the error message states that the Connection has reset that could be indicative of the server loosing connection to your application. In short, the connection to the server is made, but when you start to talk to the server it resets the connection.

Take that with a grain of salt because the code you have supplied does not seem to be the raw code that is handling the socket itself, so I cannot speak on the behalf of the code.

Tldr;
Server is timing out so the connection is resetting. Could also be the code actually handling the socket



Related Topics



Leave a reply



Submit