title: Correct way to close a socket and ObjectOutputStream?
body: <p>I am writing a networked application in Java, to communicate between the client and the server I am using serialized objects to represent data/commands and sending them through object output/input streams.</p>
  
  <p>I am having problems cleanly closing the connections, I assume that I am missing something fundamental that I do not really know about, I've never used sockets with serialization before.</p>
  
  <p>What ever order I try to shutdown the connection (close client first, close server first) a <code>ConnectionReset</code> exception is thrown.  I cannot catch this exception as the client runs in another thread to the rest of the program constantly listening for messages, this must be done, as in Java <code>socket.read()</code> is a blocking method.</p>
  
  <p>What is the correct way to close a socket that I am using to send objects?</p>