Search code examples
javasocketsnetwork-programmingtcptcpsocket

SocketException Connection Reset


I created a server which accept TCP connection . After connected to socket it looping for reading data from input stream.

Steps:

  1. I started my server.
  2. Start Client.

Now I am closing client.

Then Server gives me SocketException Connection Reset

How do I check that my client is alive or not before reading from input stream.


Solution

  • If your server gets a 'connection reset' it is probably writing to a connection that has already been closed by the other end. A browser whose user presses the 'back' button is a good example. If this is an expected condition, ignore the exception. If it constitutes an application protocol error, debug the application.