T
Trecius
Hello, Newsgroupians:
In regards to reading a stream, I know we use the Read() method. One could
implement reading a stream using a while-loop.
while (stream.Read(buffer, 0, buffer.Length) != 0)
{
// Process the buffer
}
However, there's a flaw with this implementation. Let's say the buffer is
256 bytes long. Some information is sent down the stream, which is on the
other end, that is 64 bytes long. On our end the stream is Read(), and it
reads all 64 bytes. Well, once read, it will jump back up to the
while(stream.Read(...)) and just wait there until timeout. This isn't very
efficient.
In my case I know the stream's terminating string. It's a the string ###.
Would it be wise for me to watch for the termination string in my while-loop
and jump out of it when I detect it?
If it is wise of me to do it, should I be worried about the termination
string on a packet boundary? For example, the end of one packet may contain
## and then terminates. This packet is then followed by another packet
containing the final #. Should I put in previsions for this situation? Is
there a more simplistic method that I should be using?
Thank you, all.
Trecius
In regards to reading a stream, I know we use the Read() method. One could
implement reading a stream using a while-loop.
while (stream.Read(buffer, 0, buffer.Length) != 0)
{
// Process the buffer
}
However, there's a flaw with this implementation. Let's say the buffer is
256 bytes long. Some information is sent down the stream, which is on the
other end, that is 64 bytes long. On our end the stream is Read(), and it
reads all 64 bytes. Well, once read, it will jump back up to the
while(stream.Read(...)) and just wait there until timeout. This isn't very
efficient.
In my case I know the stream's terminating string. It's a the string ###.
Would it be wise for me to watch for the termination string in my while-loop
and jump out of it when I detect it?
If it is wise of me to do it, should I be worried about the termination
string on a packet boundary? For example, the end of one packet may contain
## and then terminates. This packet is then followed by another packet
containing the final #. Should I put in previsions for this situation? Is
there a more simplistic method that I should be using?
Thank you, all.
Trecius