title: Method ends when reading TCP socket data
body: <p>I am trying to capture all data sent via a TCP Port, <a href="https://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener(v=vs.110).aspx" rel="nofollow noreferrer">based on this tutorial</a>. However once all of the data has been gathered the statement randomly ends on </p>
  
  <pre><code>i = stream.Read(bytes, 0, bytes.Length)
  </code></pre>
  
  <p>Once the <code>while</code> loop has gathered all the data I need to then use this lower down, not for it to just stop. No errors are thrown either. How should I do this?</p>
  
  <pre class="lang-vb prettyprint-override"><code>i = stream.Read(bytes, 0, bytes.Length)
  While(i&lt;&gt; 0)
      data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
      'On second loop, once all data has been gathered, the program just drops out after this line
      i = stream.Read(bytes, 0, bytes.Length)
      MessageBox.Show(data)
  End While
  </code></pre>