Re: works on console but not when writing to a string or file
- From: "Peter Duniho" <NpOeStPeAdM@xxxxxxxxxxxxxxxx>
- Date: Thu, 16 Oct 2008 11:50:34 -0700
On Thu, 16 Oct 2008 11:39:01 -0700, Kumar <Kumar@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am using granados telnet client for connecting to the telnet and get the
data from it. Every thing appears to be going smooth. But for some reason
when I try to write the byte data to a string or streamwriter, it looses the
final packet. Strangely, If I output the datapackets to a console from the
telnet server, it perfectly gets all the output packets.
Why is that strange? I would think that what's strange is that your code doesn't work, not that some other code does. :)
the code snippet is below:
StreamWriter sw = new StreamWriter("c:\\output.txt", true);
public void OnData(byte[] data, int offset, int length)
{
System.Console.Write(Encoding.ASCII.GetString(data, offset,
length));
outputdata = (Encoding.ASCII.GetString(data, offset, length));
sw.Write(outputdata);
//sw.Close();
}
in the above,
System.Console.Write(Encoding.ASCII.GetString(data, offset, length));
outputs the data correctly, however,
in the outputdata string the last packets gets chopped off.
Are you _sure_ that "in the outputdata string the last packets gets chopped off"? That is, have you stepped through the debugger and confirmed that you are missing data in the string itself?
Can someone help me understand what's happening behind. Or is it something I
am missing while writing to a string or file.
Well, commenting out the call to StreamWriter.Close() can't possibly be helping matters. Failing to close a StreamWriter when you're done with it is certainly one way that files wind up shorted of data.
But you've specifically said the data is lost before you even get as far as writing to the StreamWriter, which implies a problem somewhere else.
Unfortunately, without a concise-but-complete code sample that reliably demonstrates the problem, it's nearly impossible to provide any specific advice. At the very least, you need to be more precise about the problem description.
Pete
.
- Follow-Ups:
- References:
- Prev by Date: Re: ArrayList vs. List
- Next by Date: Re: ArrayList vs. List
- Previous by thread: works on console but not when writing to a string or file
- Next by thread: Re: works on console but not when writing to a string or file
- Index(es):
Relevant Pages
|