title: Java TCP/IP Server Closing Connections Improperly
body: <p>I've created an MMO for the Android phone and use a Java server with TCP/IP sockets. Everything generally works fine, but after about a day of clients logging on and off my network becomes extremely laggy -- even if there aren't clients connected. NETSTAT shows no lingering connections, but there is obviously something terribly wrong going on.</p>
  
  <p>If I do a full reboot everything magically is fine again, but this isn't a tenable solution for the long-term. This is what my disconnect method looks like (on both ends):</p>
  
  <pre><code>    public final void disconnect()
  {
      Alive = false;
      Log.write("Disconnecting " + _socket.getRemoteSocketAddress());
      try
      {
          _socket.shutdownInput();
      }
      catch (final Exception e)
      {
          Log.write(e);
      }
      try
      {
          _socket.shutdownOutput();
      }
      catch (final Exception e)
      {
          Log.write(e);
      }
      try
      {
          _input.close();
      }
      catch (final Exception e)
      {
          Log.write(e);
      }
      try
      {
          _output.close();
      }
      catch (final Exception e)
      {
          Log.write(e);
      }
      try
      {
          _socket.close();
      }
      catch (final Exception e)
      {
          Log.write(e);
      }
  }
  </code></pre>
  
  <p>_input and _output are BufferedInputStream and BufferedOutputStream spawned from the socket. According to documentation calling shutdownInput() and shutdownOutput() shouldn't be necessary, but I'm throwing everything I possibly can at this.</p>
  
  <p>I instantiate the sockets with default settings -- I'm not touching soLinger, KeepAlive, noDelay or anything like that. I do not have any timeouts set on send/receive. I've tried using WireShark but it reveals nothing unusual, just like NETSTAT.</p>
  
  <p>I'm pretty desperate for answers on this. I've put a lot of effort into this project and am frustrated with what appears to be a serious hidden flaw in Java's default TCP implementation.</p>