Determine Exact Upload Speed?

Mohit Shrivastava

I wanted to check the upload speed of the system.

void CheckUploadSpeed()
{
    using (var wc = new WebClient())
    {
        IPv4InterfaceStatistics ipis = networkInterface.GetIPv4Statistics();
        BytesSentb4Upload = ipis.BytesSent;
        FileStream stream = File.OpenRead(string.Format("{0}speedtext.txt", path)); //speedtext.txt is a 5 MB file.
        var fileBytes = new byte[stream.Length];
        stream.Read(fileBytes, 0, fileBytes.Length);
        stream.Close();
        startTime = Environment.TickCount; 
        wc.UploadDataAsync(new Uri("http://www.example.com/"), fileBytes);
        InternetSpeedResult = "Data upload started. Uploading 5MB file";
        wc.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
        wc.UploadDataCompleted += wc_UploadDataCompleted;
    }
}

And on Upload Progress Changed

void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
{
    InternetSpeedResult = string.Format("Checking Upload Speed ... ");
    double endTime = Environment.TickCount; 
    double secs = Math.Round(Math.Floor(endTime - startTime) / 1000, 0); 
    if (secs >= 30) 
    { 
        UploadComplete(sender, e); 
    }
}

This code actually is serving my issue but the problem is that this is not giving the exact results everytime. Since I am counting on Complete BytesSent in the particular period of time. This numbers automatically varies. If the Speed is very low (less than 512 KBPS) and very high (Greater than 20 MBPS) than its not giving the expected upload rate.

  1. What should I be doing in the code that I can rely on the Results?
  2. Is there any other approach to check the Upload Speed
  3. If the Speed is very low (less than 512 KBPS) and very high (Greater than 20 MBPS). What approach should I take?
user5245673

I would not say this as a solution whereas it would be small workaround which might help you to get rely on your upload speed.

Increase the size of the uploaded file to somewhere around 100MB or so. Set the secs >= 60

Now whatever the speed of the network is if it low it would check for a minute and let u know the upload speed. If it is higher. Then also it would let u know either all 100 MB is transferred and you will get the upload speed and if not than you you'll get to know the speed in 60 seconds.

Since working with high speed internet the problem is that the bandwidth is not optimum while the transaction begins. as soon as you start sending or receiving data it will increase the speed thus Changing it to 60 seconds and increasing the file size will give you results in both the cases.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Determine maximum RAM speed

From Dev

Calculate upload speed

From Dev

File Upload speed factors

From Dev

Determine exact properties applied by Button

From Dev

algorithm for using download speed to increase upload speed

From Dev

Upload speed much higher than download speed:

From Dev

Get upload/download kbps speed

From Dev

iOS NSUrlConnection check upload speed

From Dev

Get network Download and Upload speed

From Dev

no upload speed on one computer only

From Dev

cURL Upload/Download Speed Test

From Dev

Determine exact screen flip times on Android

From Dev

Read file with findstr to determine exact results

From Dev

Given two doubles, how to determine if their quotient is exact?

From Dev

Determine available upload/download bandwidth

From Java

Android: How to determine Network speed in android programmatically

From Dev

How to determine the speed of my angular webpage?

From Dev

OBDII - determine gear given speed and RPM

From Dev

Android: How to determine Network speed in android programmatically

From Dev

How to determine the DSL-speed of a wireless modem?

From Dev

How to determine the speed of my angular webpage?

From Dev

How to determine a network cable's maximum speed?

From Dev

Not Able to Upload Image Exact Specified Dimensions

From Dev

Limit VirtualBox guest upload speed (but not download speed) on Windows host

From Dev

How to get Tomcat upload/download speed with JMX

From Dev

Way to limit azure blob upload speed

From Dev

Java httppost file post print upload speed

From Dev

How does using CloudFront improve upload speed?

From Dev

Dropbox upload slows internet speed drastically

Related Related

HotTag

Archive