I'm connecting to a remote PC via a TCP socket. I can connect fine but I only seem to get one chunck of data.

I thought that the code below would continuously request data from the remote PC and, for now, dump the data to a message box. This works the first time through, kind of.

Here's what happens: I'm asking for 1000 bytes of data (The remote PC sends more that 1000 bytes). I get this data and it is displayed properly. I thought that my second request for data would overwrite the existing buffer, instead what I get is the second 1000 bytes of the first request. This happens until the original buffer is empty then my message box appears with no text (only the OK button os visible).

Can any one see what I'm missing? This is my first attempt at sockets so most of my code is cut and paste. Still trying to decipher what it all means.

VB Code:
  1. 'Not really using this IP Address
  2.     Private pierAddress as String = "127.0.0.1"
  3.     Private telnetPort as Integer = 23
  4.     Private tcp as New TcpClient
  5.  
  6.     Private SubRefreshPlotData
  7.         Dim Done as Boolean = False
  8.  
  9.         Do While Not Done
  10.             getKrData()
  11.             Thread.CurrentThread.Sleep(500)
  12.         Loop
  13.     End Sub
  14.  
  15.     Private Sub getKrData()
  16.         Dim address As IPAddress = IPAddress.Parse(pierAddress)
  17.         Dim ipEndPoint As New IPEndPoint(address, telnetPort)
  18.         Dim data As Byte()
  19.         Dim responseData As String = String.Empty
  20.  
  21.         data = New Byte(999) {}
  22.  
  23.         Try
  24.             tcp.Connect(ipEndPoint)
  25.             Dim stream As NetworkStream = tcp.GetStream()
  26.             Dim bytes As Int32 = stream.Read(data, 0, data.Length)
  27.             responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
  28.         Catch e As Exception
  29.             Console.WriteLine(e.ToString())
  30.         End Try
  31.  
  32.         MessageBox.Show(responseData)
  33.  
  34.         tcp.Close()
  35.     End Sub