J
jens d
Hi NG,
I'm trying to send a XML file. The receiver should be able to work with
the content without saving it as a file. (Best with XMLReader, but that
will be part of further postings )
I tried it the following way, but it doesnt work out.
Please have a look at my code:
Sender:
long s_length = FileStream.Length;
long s_read = 0;
StreamWriter sw = new StreamWriter(NetworkStream, Encoding.UTF8, 1024);
using (StreamReader sr=new StreamReader(FileStream, Encoding.UTF8,true))
{
while (s_length > s_read)
{
char[] buffer = new char[1024];
int read = sr.Read(buffer, 0, 1024);
s_read += read;
sw.Write(buffer,0,read);
}
}
NetworkStream.Flush();
One Problem with the sender is that the StreamWriter doesnt seem to send
the buffer every time when sw.Write(..) is called.
Another, that the calculated size (s_read) is not the same as
FileStream.lenth and therefore this ends up in a 'do_nothing_loop'
Suggestions??
Receiver:
using (StreamReader sr = new StreamReader(NetworkStream, ENCODING.UTF8))
{
while(true)
{
char[] buffer = new char[1024];
int read = sr.Read(buffer, 0, 1024);
StringBuilder.Append(buffer);
if (read == 0)
break;
}
}
Within the StringBuilder I hoped to find the complete XML-file, but I
only got the first 1024bytes as it seems.
Does anybody see a mistake?
Do you know a better way to send the file?
Somebody done this before? -> Links, Tutorials?
Thanks a lot
Jens
I'm trying to send a XML file. The receiver should be able to work with
the content without saving it as a file. (Best with XMLReader, but that
will be part of further postings )
I tried it the following way, but it doesnt work out.
Please have a look at my code:
Sender:
long s_length = FileStream.Length;
long s_read = 0;
StreamWriter sw = new StreamWriter(NetworkStream, Encoding.UTF8, 1024);
using (StreamReader sr=new StreamReader(FileStream, Encoding.UTF8,true))
{
while (s_length > s_read)
{
char[] buffer = new char[1024];
int read = sr.Read(buffer, 0, 1024);
s_read += read;
sw.Write(buffer,0,read);
}
}
NetworkStream.Flush();
One Problem with the sender is that the StreamWriter doesnt seem to send
the buffer every time when sw.Write(..) is called.
Another, that the calculated size (s_read) is not the same as
FileStream.lenth and therefore this ends up in a 'do_nothing_loop'
Suggestions??
Receiver:
using (StreamReader sr = new StreamReader(NetworkStream, ENCODING.UTF8))
{
while(true)
{
char[] buffer = new char[1024];
int read = sr.Read(buffer, 0, 1024);
StringBuilder.Append(buffer);
if (read == 0)
break;
}
}
Within the StringBuilder I hoped to find the complete XML-file, but I
only got the first 1024bytes as it seems.
Does anybody see a mistake?
Do you know a better way to send the file?
Somebody done this before? -> Links, Tutorials?
Thanks a lot
Jens