title: Java - readObject() and setSoTimeout()
body: <p>So, i wrote a thread on my client side , which tries to <code>readObject()</code> from a socket stream.</p>
  
  <p>This thread runs as long the client is connected.</p>
  
  <p>The connection to the server can be closed on the client's GUI.
  If the client decides to disconnect(this will not exit the client program) by clicking the 
  "disconnect" menu option, the socket will be closed and a <code>isConnected</code> is set to false.</p>
  
  <p>Since the clients read thread tries to <code>readObject()</code> from stream, while the connection can be closed via the GUI, i set a timeout to 250ms (<code>setSoTimeout(250)</code>).</p>
  
  <pre><code>@Override
  public void run()
  {
    this.connection = this.connectionHandler.getSocket();
    while(connectionHandler.isConnected())
    {
      this.readCircle();
    }
    this.connectionHandler.setReadTaskRunning(false);
  }
  
  private void readCircle()
  {
    try
    {
      this.connection.setSoTimeout(250);
      this.connectionHandler.readData(); //this uses readObject().
    }
   catch(SocketTimeoutException timeout){}
   catch(...){}
  </code></pre>
  
  <p>}</p>
  
  <p>I know that <code>readObject()</code> will block, and to check if the client is still connected, i wraped it in a <code>while</code>, which checks (every timeout) if the client socket is still connected.</p>
  
  <p>My question now:</p>
  
  <p>In case, if the <code>readObject()</code> starts to get a object passed by the server, tries to read it, but while processing a timeout occurs, will the data on the stream be "damaged" in some way, because it canceled.
  Or should i just let the <code>readObject()</code> block and catch a exception if the GUI thread wants to close the socket.</p>
  
  <p>I'm not very experienced with sockets and maybe my approach is wrong at all.</p>