Thursday 15 May 2014

.Net C# TcpClient / Socket HTTP Client Performance / Efficiency -


I am writing an HTTP client using .Net TcpClient / Sockets.

So far, the customer handles both content-length and clock responses through the network-stream response (after writing the GET request for the TCP client), parsing the header and the relevant message body byte Retrieving / Checked Bytes To do this, it uses the NetworkStream ReadByte method.

All this works well, but performance is an important consideration so I would like to make it as quick and efficient as possible.

Initially read this message body (depending on content-length) or ReadByte for selected body body bytes in a proper size buffer, in all other areas, readbits (like headers, chunk Reading size etc.).

I'm interested in knowing better / different ways to do this to get optimum performance? Obviously, the main problem with HTTP is that unless it is retrieved, the length of the reaction stream is not known.

There is a special reason for this that I am not using more arrays (for example, HttpWebRequest) for this (I need better control at the socket level).

Many thanks,

Chris

I recommend using a process with size buffer, fill buffer until repeated response stream is over. When the buffer completes or ends the stream, attach the buffer content to the string (or whatever you are using to store the message).

If you want to read an important bit information in a hurry, just read enough of the stream to see it (in other words, you do not need to fill the buffer first on the pass if you do not want to ).

You should also consider using an event system to indicate the presence of new data, which is shaped in such a way that the main part of your process is given this address Karan Not that data where it came from need or you are how buffer.

Edit

In response to your comment question, if you have a connection, in which you try to reuse it for many requests , You can create the thread that reads more than it when it finds the data, then it uses the event to push it out to handle the main part of your program. I do not have any specimen, but you should be able to find many with Bing or Google searches.


No comments:

Post a Comment