Hi. using .NET 2.0 C# here.

This is such a frustration. I spent over 10 hours solid looking at this and still cant find the solution.

I have a Server and Client. Both use XML Serialization.

Sometimes the Client does not recieve the full xml serialized string and throws me an error. I then investigate and find that it seems to be the listening area thats the problem.

I can see the Server sent the full serialized string, the client sometimes (more often than being less) doesnt recieve the full thing, therefore when it tries to deserialize, it will throw an error.

When I look at it, only part of the string seems to have reached the client, or from what it is reading. Why? how?

how can I read the entire stream?

This is the code I have now, and seems to have improved than before but still get the errors:

Code:
//listening port
int theData = 0;
byte[] theIncomingDataBuffer = new byte[this.theNumberOfBytesToRead];
while (this.theNetworkStream.DataAvailable)
{ 
   theData += this.theNetworkStream.Read(theIncomingDataBuffer, 0, theIncomingDataBuffer.Length);
                        
}
if (theData > 0)
{
              
   this.theIncomingDataManager.DoAnalyzeData(System.Text.Encoding.ASCII.GetString(theIncomingDataBuffer, 0, theData)); 
}

Why isnt the client picking up the full string at times? The buffer size is Int16.MaxValue (32726) so the buffer is more than enough.