473,395 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

NetworkStreams

Ron
Hi all,

I created a POP3 client (with the help of some examples of the net:).
I'm using a StreamReader to read from the NetworkStream as follows:
while (sTmp != ".")
{
sMsg += sTmp + "\r\n";
sTmp = strmReader.ReadLine();
}

The problem is that this is really slow and uses a lot of CPU time.

Is there a faster way to do this??

Thanx,
Ron
Nov 16 '05 #1
4 1485
Your string concatenation is going to kill you. You'd be better off using
a collection or array based storage for holding each individual string and
then joining them later. I do approximately the same operations for
newsgroups, downloading at over 1mbit per second while reconstructing
and decoding on a pretty lame machine. Never seen more than 10-15%
CPU utilization for these processes.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Ron" <rv*******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi all,

I created a POP3 client (with the help of some examples of the net:).
I'm using a StreamReader to read from the NetworkStream as follows:
while (sTmp != ".")
{
sMsg += sTmp + "\r\n";
sTmp = strmReader.ReadLine();
}

The problem is that this is really slow and uses a lot of CPU time.

Is there a faster way to do this??

Thanx,
Ron

Nov 16 '05 #2

"Ron" <rv*******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi all,

I created a POP3 client (with the help of some examples of the net:).
I'm using a StreamReader to read from the NetworkStream as follows:
while (sTmp != ".")
{
sMsg += sTmp + "\r\n";
sTmp = strmReader.ReadLine();
}

The problem is that this is really slow and uses a lot of CPU time.

Is there a faster way to do this??


Where is your slow down occuring? Is it in building sMsg or is it in the
call to strmReader.ReadLine()?

If its in building sMsg, you may want to look at System.Text.StringBuilder,
if its in strmReader.ReadLine(), you may get better performance by copying
large blocks into a MemoryStream and doing your parsing from there.
Nov 16 '05 #3
Ron
It was indeed the string concatenation. I am using the StringBuilder now,
and it has decreased the cpu usage dramatically.

Thanks.
Ron
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:#z**************@TK2MSFTNGP15.phx.gbl...

"Ron" <rv*******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
Hi all,

I created a POP3 client (with the help of some examples of the net:).
I'm using a StreamReader to read from the NetworkStream as follows:
while (sTmp != ".")
{
sMsg += sTmp + "\r\n";
sTmp = strmReader.ReadLine();
}

The problem is that this is really slow and uses a lot of CPU time.

Is there a faster way to do this??
Where is your slow down occuring? Is it in building sMsg or is it in the
call to strmReader.ReadLine()?

If its in building sMsg, you may want to look at

System.Text.StringBuilder, if its in strmReader.ReadLine(), you may get better performance by copying
large blocks into a MemoryStream and doing your parsing from there.

Nov 16 '05 #4

"Ron" <rv*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
It was indeed the string concatenation. I am using the StringBuilder now,
and it has decreased the cpu usage dramatically.

I suspected that it was, but it was possible that you were experiancing come
obscure bug caused by something with your socket settup, thats why I
suggested both, ;).

Depending on your purposes, Justin's suggestion may be better. If you are
decoding attachments or multipart mime messages it almost certainly is, but
if you are just sucking out plain text messages StringBuilder will work
fine. Thanks.
Ron
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> wrote in
message news:#z**************@TK2MSFTNGP15.phx.gbl...

"Ron" <rv*******@hotmail.com> wrote in message
news:eJ**************@TK2MSFTNGP12.phx.gbl...
> Hi all,
>
> I created a POP3 client (with the help of some examples of the net:).
> I'm using a StreamReader to read from the NetworkStream as follows:
> while (sTmp != ".")
> {
> sMsg += sTmp + "\r\n";
> sTmp = strmReader.ReadLine();
> }
>
> The problem is that this is really slow and uses a lot of CPU time.
>
> Is there a faster way to do this??


Where is your slow down occuring? Is it in building sMsg or is it in the
call to strmReader.ReadLine()?

If its in building sMsg, you may want to look at

System.Text.StringBuilder,
if its in strmReader.ReadLine(), you may get better performance by
copying
large blocks into a MemoryStream and doing your parsing from there.


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Skwerl | last post by:
Hi guys. I've written code to embed an ICC profile in a TIFF image, and I think my IO operations are slowing things down. It is taking about a second to embed each tag in 7-meg TIFF files. ...
3
by: מורדי | last post by:
Hi, I'm writing a client/server application in which the client send a series of screenshots to the server to be saved using the tcpclient. in most cases the first screenshot is transmitted ok...
0
by: Thomas Zöchling | last post by:
Hat jemand (schlechte) Erfahrungen mit Asynchronen NetworkStreams gemacht? In meiner Serveranwendung scheint die BeginRead Methode des NetworkStreams manchnmal den Stream nicht fertig zu lesen. ...
2
by: Nad | last post by:
Hello All, I have been trying to get some sort of documantion on how StreamReader.ReadToEnd() finds out if the stream has ended and if anyone can read the following lines and tell me how to...
6
by: Stephen Brooker | last post by:
Hi all, I've got a basic TCP app that is giving me trouble. I have a separate class that takes care of the TCP connection, and uses the NetworkStreams BeginRead and EndRead with a callback...
9
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
3
by: Adie | last post by:
I'm using TcpClient in blocking mode with NetworkStreams and would like to be able to give notification that data was sent - I presume this must be possible? But anyone know how?
10
by: Alejandro Castañaza | last post by:
Hi. I'm writing a program, and I need to send confidential data through the network, so I decided to use encryption, using the System.Security.Cryptography namespace. I'm using the sockets...
6
by: Ryan Liu | last post by:
Hi, I have some basic question about NetworkStream, can someone explain to me? Thanks a lot in advance! TcpClient has a GetStream() method return a NetworkStream for read and write. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.