For my current project, I need to request XML data through a tcp / ip socket connection. For this, I use the TcpClient class:
Dim client As New TcpClient() client.Connect(server, port) Dim stream As NetworkStream = client.GetStream() stream.Write(request) stream.Read(buffer, 0, buffer.length)
Now it works fine and dandy for small answers. However, when I start receiving large blocks of data, it seems that the data is getting through the socket connection in bursts. When this happens, calling stream.Read only reads the first packet, and thus, I skip the rest of the response.
What is the best way to deal with this problem? Initially, I tried to just loop around until I had a valid XML document, but I found that between the stream. Reading causes the underlying thread to sometimes shut down, and I skip the last piece of data.
source share