all groups > dotnet xml > february 2005 >
You're in the

dotnet xml

group:

XmlTextReader TCP Socket


XmlTextReader TCP Socket Stelrad Doulton
2/25/2005 10:51:06 PM
dotnet xml: Hi all,

This is repost from dotnet.general, I have only just found this forum.

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). I realise there is refactoring to do, as I said this
was a quick and dirty workaround but the question holds.

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


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);

}




Re: XmlTextReader TCP Socket Derek Harmon
2/26/2005 10:22:08 PM
[quoted text, click to view]

Joe Hildebrand first devised a solution for this problem in his post
to the 'gmane.network.jabber.lib.net' newsgroup on Sep 14, 2004.
The jist of which as I understood it is that you must wrap incoming
packets to make them appear to be 4,096 bytes in length by padding
them with trailing WS. The issue is the XmlTextReader constructor
will block until it's read 4,096 bytes or the Stream ends, whichever
comes first. You want to make sure it sees the 4,096 bytes, even
when your opening XML stanzas may be less than that.


Derek Harmon

Re: XmlTextReader TCP Socket Stelrad Doulton
2/27/2005 11:37:01 AM
Thanks Derek,

Have you got a link to the original thread?

[quoted text, click to view]

Re: XmlTextReader TCP Socket Stelrad Doulton
2/27/2005 1:30:57 PM
Cheers

[quoted text, click to view]

Re: XmlTextReader TCP Socket Martin Honnen
2/27/2005 1:46:27 PM


[quoted text, click to view]


[quoted text, click to view]

I think the list is archived here:
<http://news.gmane.org/gmane.network.jabber.lib.net/cutoff=223>
but I haven't looked for that particular post.


[quoted text, click to view]

--

Martin Honnen
AddThis Social Bookmark Button