title: stream connection using httpwebrequest
body: <p>I have created a httpwebrequest connection to a streaming API after trying a tTCPClient which just never ended up working.  My concern is whether my code is correct and that I am actually reading in new data and that the connection is maintained. Initially I had been reading into a buffer and just loaded everything into a file after max size, but figured it would be simpler to read a line, since each entry was being sent delimited by line feeds.</p>
  
  <pre><code>rStream = webrequest.GetResponse().GetResponseStream
  rStream = New GZipStream(rStream, CompressionMode.Decompress)
  If rStream.CanRead then
     Dim bufferPit(8100) as byte
     Do
        Dim dStream as StreamReader = New StreamReader(rStream)
        While not dStream.EndOfStream
            rData = dStream.ReadLine()
            pTools.appendToFile(rData)
        End While
     .....//some other exception handling
     Loop While rStream.CanRead
  </code></pre>
  
  <p>It looks like I am continuously reading and not sure if I am reading redundant data here. Also another question is that if I were to use a thread to appendToFile, would that maintain the connection to the stream?</p>