title: Do I need to keep the TcpClient/TcpListener after establishing a connection?
body: <p>I would like to implement a <code>TcpConnection</code> class wrapping a <code>Socket</code> or <code>NetworkStream</code>, and I would like to abstract this connection from whether it is a server or client, since my aplication can run in either mode.</p>
  <p>e.g <code>TcpConnection.TcpConnection(NetworkStream stream)</code> would be the constructor signature and these would be created using <code>TcpClient</code> or <code>TcpListener</code> maybe in some sort of factory.</p>
  <p>I can't tell from the documentation if I need to keep those <code>TcpClient</code> or <code>TcpListener</code> objects afterwards in terms of the lifetime of my stream/socket. Obviously I don't want to leave these objects floating around, I either want to retain a reference or dispose them.</p>
  <p>The documentation for <a href="https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.tcpclient.getstream?view=netcore-3.1" rel="nofollow noreferrer">NetworkStream says:</a></p>
  <blockquote>
  <p>You must close the NetworkStream when you are through sending and
  receiving data. <strong>Closing TcpClient does not release the NetworkStream</strong>.</p>
  </blockquote>
  <p>This suggests the stream (and presumably the same for a socket) is <em>never</em> reliant on the client/listener - is that correct?</p>