1

I am writing an internet speed measurer. I want to measure internet speed without saving remote file to either file or memory - I need fetch the data and forget it, so it seems that WebClient and StreamReader is not good for it (maybe i should inherit them and override some private methods). How to make it?

KOLANICH
  • 2,904
  • 2
  • 20
  • 20
  • Why dont you want to save to memory, it seems like the most logical way to do this, Downlaod a byte array, when done bytes / time = speed – sa_ddam213 Jul 14 '13 at 22:29
  • Because the file can be either very large or have infinite length. Also I think that saving info anywhere if it is not needed is bad. I want to have an interface like WebClient (or maybe StreamReader, if it is easyer to implement) has (setting it up and then get events with progress) but save tata to nowhere. – KOLANICH Jul 14 '13 at 22:45
  • do you want to measure throughput (download/upload speed) on a particular network interface? – Bojan Komazec Jul 14 '13 at 23:00
  • I want to measure internet speed. The measurer will download data from remote host and then upload data to it. No need to save downloaded data. No need to upload real file. Downloaded data must be forgot, uploaded data is generated randomly. (we need only know the time the uploading/downloading take and the size of uploaded/downloaded data). – KOLANICH Jul 15 '13 at 10:02

2 Answers2

3

I think that when writing such a system you should also select exactly which size of file you want to download. Anyway, you can maybe download parts of the file if the "very large" or "infinite" size is a problem. You can maybe use HttpWebRequest.AddRange http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.addrange.aspx

AJ222
  • 1,114
  • 2
  • 18
  • 40
1

You can use System.Net.WebRequest to measure the throughput, using asynchronous calls to capture the data as it is being read.

The MSDN example code for WebRequest.BeginGetResponse shows one method for using the asynchronous methods to read the data from a remote file as it is being received. The example stores the response data in a StringBuilder, but you can skip that since you're not actually interested in the data itself.

I added some timing code to their example and tested it against a couple of large file downloads, seems to do the job you need it for.

Corey
  • 15,524
  • 2
  • 35
  • 68