views:

146

answers:

3

There seems to be some confusion as well contradicting statements on various SO answers: http://stackoverflow.com/questions/585599/whats-causing-my-java-net-socketexception-connection-reset . You can see here that the accepted answer states that the connection was closed by other side. But this is not true, closing a connection doesn't cause a connection reset. It is cauesed by "an underlying TCP/IP error."

What I want to know is if a SocketException: Connection reset means really besides "unerlying TCP/IP Error." What really causes this? As I doubt it has anything to do with the connection being closed (since closing a connection isn't an exception worthy flag, and reading from a closed connection is, but that isn't an "underlying TCP/IP error."

My hypothesis is this

Connection reset is caused from a server's failure to acknowledge an ACK packet (either wholly or just improperly as per TCP/IP). And that a SocketTimeoutException is generated only when no data is generated to be read (since this is thrown during a read after a certain duration, and read is waiting for data, but is not concerned with ACK packets). In other words, read() throws SocketTimeoutException if it didn't read any bytes of actual data (DATA LAYER) in its allotted time.

+1  A: 

In my experience, it happens when the client aborts a request (user closed the tab or clicked another link).

Guillaume
You're a bit talking in webapplication context. The question seems not to be about webapplications.
BalusC
I'm not sure what the question really is, but the linked question showed a Tomcat error log. The 'connection reset' message definitively occurs when the clients abruptly closes the connection, maybe in other situations too though.
Guillaume
+1  A: 

From the openjdk6 sources, it appears that the "Connection reset" is issued when an attempt to read data fails with an ECONNRESET error (Linux & Solaris) or WSAECONNRESET (Windows).

In my experience the typical cause is the party on the other end of the socket closed the socket without first performing a shutdown.

Devon_C_Miller
A: 

Here in my case the problem seems to be little complicated!!

In my application, i am sending a file basically i am connecting to a server which acts as windows service! and waiting for responsee!!

but what is happing here is, if i use BufferedWriter i wont get the connection reset problem..

OutputStream os = socket.getOutputStream(); BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(os)); wr.write(request);

But when i code like below I will get the error.

OutputStream os = socket.getOutputStream(); os.write(mybytearray, 0, mybytearray.length);

In simple, I am getting error only when i am using SocketInputStream and SocketOutputStream.

Do anyone have any idea on this?

chetan shettigar
Wireshark would be very informative. I believe the conn reset comes from a connection being established and never closed correctly because the client or server stops responding to TCP requests (most likely because it crashed or is unable to respond).
Zombies