Hi all,
I am writting a Jabber-esque client-server application and have run into an
issue with the XmlTextReader constructor when passing a NetworkStream - It
hangs forever, apparently this is an issue with SP1.
Anyway I have the code below as a work around (using bool keepalives as it
must run on the CF):
while(keepAlive)
{
//do the blocking read on one thread
NetworkStream readStream = new NetworkStream(this.socket, false);
while(!readStream.DataAvailable && keepAlive)
{
Thread.Sleep(100);
}
if(!keepAlive)
break;
MemoryStream memStream = new MemoryStream();
byte[] buffer = new byte[256];
int bytes = 0;
do
{
bytes = readStream.Read(buffer, 0, buffer.Length);
memStream.Write(buffer, 0, bytes);
}while(readStream.DataAvailable);
memStream.Seek(0, SeekOrigin.Begin);
if(DataAvailable != null)
DataAvailable(memStream);
}
My grasp of TCP/IP is still tenuous but I am concerned that a very large
file coming in very slowly could be a problem. Could this code empty the
underlying Socket buffer and return an incomplete stream?
Thanks