S
sdf
Hey all, I have a problem here. I got some code from the web/a book (it
was actually the exactly the same), on how to do NNTP. The code works except
it's VERY cpu intensive and VERY slow. I looked into the code and noticed it
calls a Response method over and over, each time it returns a line of text.
The problem is the method itself. Response() reads data from the
NetworkStream 1 byte at a time! This of course is a terrible idea, and takes
forever. I know there's got to be a better way, b/c outlook express(which
I'm using to write this) pulls up newsgroups really fast. I've posted the
method on the end of this message. I can't seem to get the thing to go
faster - I've tried BufferedStream, StreamReader, etc. - They all read part
of the message and then block indefintly on the read method.
Hope someone can come up with something, I tried the web and no one will
answer this one.
Thanks,
Nick
Code:
private string Response()
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte [] serverbuff = new Byte[4096];
NetworkStream stream = GetStream();
int count = 0;
byte[] buff = new byte[1];
while (true)
{
int bytes = stream.Read(buff, 0, 1 );
if (bytes == 1)
{
serverbuff[count] = buff[0];
count++;
if(count > serverbuff.Length - 5)
break;
if (buff[0] == '\n')
{
break;
}
}
else
{
break;
};
};
was actually the exactly the same), on how to do NNTP. The code works except
it's VERY cpu intensive and VERY slow. I looked into the code and noticed it
calls a Response method over and over, each time it returns a line of text.
The problem is the method itself. Response() reads data from the
NetworkStream 1 byte at a time! This of course is a terrible idea, and takes
forever. I know there's got to be a better way, b/c outlook express(which
I'm using to write this) pulls up newsgroups really fast. I've posted the
method on the end of this message. I can't seem to get the thing to go
faster - I've tried BufferedStream, StreamReader, etc. - They all read part
of the message and then block indefintly on the read method.
Hope someone can come up with something, I tried the web and no one will
answer this one.
Thanks,
Nick
Code:
private string Response()
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte [] serverbuff = new Byte[4096];
NetworkStream stream = GetStream();
int count = 0;
byte[] buff = new byte[1];
while (true)
{
int bytes = stream.Read(buff, 0, 1 );
if (bytes == 1)
{
serverbuff[count] = buff[0];
count++;
if(count > serverbuff.Length - 5)
break;
if (buff[0] == '\n')
{
break;
}
}
else
{
break;
};
};