title: How to close a TcpClient when the other end has been closed in .NET?
body: <p>I have a class that handles TcpClients. What the class should do is:</p>
  
  <pre><code>    while the other end has not done a graceful close or we are stopping
      {
          receive a request
          process it
          send response
      }
  </code></pre>
  
  <p>As I don't know when the other client will send a request I can not do a Read with a timeout set, so what I have until now is this:</p>
  
  <pre><code>    While Not Me.Stopping()
          Try
              If tcpClient.Available &gt;= My.Settings.minimumModBusTcpFrameSize Then
                  processer = New MessageProcesser(Me, tcpClient)
                  processer.ProcessMessage()
              End If
          Catch ex As TimeoutException
              ''#Do not nothing, the current message will timeout on origin too.
          End Try
      End While
  </code></pre>
  
  <p>The problem with this approach is that I never know when a client has done a remote call to Close().</p>
  
  <p>Is there a way of solving this problem?</p>