java.net.SocketException: Connection reset by peer: socket write error When serving a file
It is possible for the TCP socket to be "closing" and your code to not have yet been notified.
Here is a animation for the life cycle. http://tcp.cs.st-andrews.ac.uk/index.shtml?page=connection_lifecycle
Basically, the connection was closed by the client. You already have throws IOException
and SocketException
extends IOException
. This is working just fine. You just need to properly handle IOException
because it is a normal part of the api.
EDIT: The RST
packet occurs when a packet is received on a socket which does not exist or was closed. There is no difference to your application. Depending on the implementation the reset
state may stick and closed
will never officially occur.