0

I m developing a website which needs to vary contents according to the internet speed/bandwidth.

At places with low bandwidth the web application should just display plain text and for normal bandwidth the normal website is displayed.

I have been mulling over it since a few days yet i m not able to find a proper solution. Is there a simple way to detect bandwidth in asp.net?

Thanks

Paras
  • 2,997
  • 6
  • 35
  • 46
  • possible duplicate of [How can I find out the download speed of the client from server?](http://stackoverflow.com/questions/678635/how-can-i-find-out-the-download-speed-of-the-client-from-server) – Tim M. Sep 18 '12 at 06:35

2 Answers2

1

Follow given code to check your internet connection speed Add namespace

using System.Net;

write code on test button click event..

  Uri URL = new Uri("http://sixhoej.net/speedtest/1024kb.txt");

    WebClient wc = new WebClient();

    double starttime = Environment.TickCount;


    // download file from the specified URL, and save it to C:\speedtest.txt

    wc.DownloadFile(URL, @"C:\speedtest.txt");


    // get current tickcount

    double endtime = Environment.TickCount;


    // how many seconds did it take?

    // we are calculating this by subtracting starttime from endtime

    // and dividing by 1000 (since the tickcount is in miliseconds.. 1000 ms = 1 sec)

    double secs = Math.Floor(endtime - starttime) / 1000;


    // round the number of secs and remove the decimal point

    double secs2 = Math.Round(secs, 0);





    // calculate download rate in kb per sec.

    // this is done by dividing 1024 by the number of seconds it

    // took to download the file (1024 bytes = 1 kilobyte)

    double kbsec = Math.Round(1024 / secs);

    Label1.Text = "Download rate: " + kbsec + " kb/sec";

    try

    {

        // delete downloaded file

        System.IO.File.Delete(@"C:\speedtest.txt");

         Response.Write("Done.");

    }

    catch

    {

        Response.Write("Couldn't delete download file.");

         Response.Write("To delete the file yourself, go to your C-drive and look for the file 'speedtest.txt'.");            

    }     
Oded
  • 489,969
  • 99
  • 883
  • 1,009
user235695
  • 11
  • 1
0

Kindly check following links, Hope you will get the ideas about bandwidth checking over serving the requests

  1. Stack Answer
  2. Stack Answer
Community
  • 1
  • 1
Viral Shah
  • 2,263
  • 5
  • 21
  • 36