Search code examples
asp.netbandwidth

Building ASP.Net web page to test user's connection (bandwidth)


We need to add a feature to our website that allows the user to test his connection speed (upload/download). After some research I found that the way this being done is downloading/uploading a file and divide the file size by the time required for that task, like here http://www.codeproject.com/KB/IP/speedtest.aspx However, this is not possible in my case, this should be a web application so I can't download/upload files to/from user's machine for obvious security reasons. From what I have read this download/upload tasks should be on the server, but how? This website has exactly what I have in mind but in php http://www.brandonchecketts.com/open-source-speedtest. Unfortunately, I don't have any background about php and this task is really urgent. I really don't need to use stuff like speedtest

thanks


Solution

  • The formula for getting the downloadspeed in bit/s:

    DataSize in byte * 8 / (time in seconds to download - latency to the server).
    

    Download: Host a blob of data (html document, image or whatever) of which you know the downloadsize on your server, make a AJAX GET request to fetch it and measure the amount of time between the start of the download and when it's finished.

    This can be done with only Javascript code, but I would probably recommend you to include a timestamp when the payload was generated in order to calculate the latency.

    Upload: Make a AJAX POST request towards the server which you fill with junk data of a specific size, calculate the time it took to perform this POST.

    List of things to keep in mind:

    • You will not be able to measure higher bandwith than your servers
    • Concurrent users will drain the bandwith, build a "limit" if this will be a problem
    • It is hard to build a service to measure bandwidth with precision, the one you linked to is presenting 5Mbit/s to me when my actual speed is around 30Mbit/s according to Bredbandskollen.

    Other links on the subject

    Note: I have not built any service like this, but it should do the trick.