title: How to check upload and download speed
body: <p>I am trying to write a code for checking the upload and download speed of my ISP by using USB Dongle. The server in the dongle is Lighttpd.</p>
  
  <p>My current plan for download is to write a shell script that downloads a file from a server(the file should be big enough) and kill the process in 2 seconds.I can then get the file size.I repeat the process n times(10 here) , and take the average.Statistically i believe moving average is the best value.Please help.</p>
  
  <p>ALSO,</p>
  
  <p>My plan for upload is taking a big file(20 MB) and upload it using shell script(php also can be used), and use it to measure speed. I am not sure how to measure the upload speed here.I need bridge the communication gap, where the device hardware has the value and i need to get the proper value to be displayed to the user.Need help here.</p>
  
  <p>The Code for upload is as follows.(its a javascript file) 
  NOTE: var params is around 350 KiB</p>
  
  <pre><code>var uploadhttp;
  var url = "http://www.example.com";
  var params = 
  "RANDOM CHARACTER SET. This lone character file should be large enough";
  
  
  
  
  function getHTTPObject() {
  
      if(!uploadhttp &amp;&amp; typeof XMLHttpRequest != "undefined") 
      {
        try
          {     
          if(BrowserType=="MSIE")
              uploadhttp=new XDomainRequest(); 
          else
              uploadhttp = new XMLHttpRequest();          
          }
          catch(e)
          {
              alert(e);
          }
  /*      if(!uploadhttp){
              //alert("uploadhttp object creation failed");
              }
              else{
              //alert("uploadhttp object created successfully");
              }
   */ }
  
  }
  
  function handler() {//Call a function when the state changes.
      if(uploadhttp.readyState == 4 &amp;&amp; uploadhttp.status == 200) {
          //alert(uploadhttp.responseText);
      }
  }
  
  function getMethod() {
      getHTTPObject();
      /* if(!uploadhttp)
          //alert("failed to create object"); */
  
      if(uploadhttp)
      {
          uploadhttp.open("GET", url, true);
          uploadhttp.onreadystatechange = handler;
          uploadhttp.send(null);
      }
  }
  
  function postMethod() {
      try
      {
      getHTTPObject();
      //if(!uploadhttp)
          //alert("failed to create object");
      if(uploadhttp)
      {
          uploadhttp.open("POST", url, true);//,"jio","rancore");
      }
  
      //Send the proper header infomation along with the request
      //uploadhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  
      uploadhttp.onreadystatechange = handler;
      if(BrowserType=="MSIE")
      {
          uploadhttp.send(params);
      }
      else
      {
          var iLen = bufferedData.length;
          uploadhttp.send(bufferedData);
      }
      }
      catch(e)
      {
         alert(e);
      }
  }
  </code></pre>