Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m trying to find the download and upload speed of my connection. For that im uploading a payload to a another server and simultaneously downloading payload from the same server. This way i am able to get a download and upload speed.
The issue is that i am not being able to get values almost as that in www.speedtest.net. Here are my scripts for upload and download.

upload

C#
var uploadhttp;
var url = "http://Server/abc/";
var params =PAYLOAD(arnd 100kb)

function handler() {//Call a function when the state changes.
    if(uploadhttp.readyState == 4 && uploadhttp.status == 200) {
        alert(uploadhttp.responseText);
    }
}
function postMethod() {
    try
    {
    getHTTPObject();
    if(!uploadhttp)
        alert("failed to create object");
    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;
    uploadhttp.send(params);

    }
    catch(e)
    {
       alert(e);
    }
}
//I am callin postMethod ever 100ms so that it could upload the payload to the server hence giving me my upload speed.
//Similarly the download script is
var xhr;
 xhr = new XMLHttpRequest();
 
var data;

function getDownload()
{
	try
	{	
		xhr.onreadystatechange=function()
		{
			if (xhr.readyState==4 && xhr.status==200)
			{
				//alert(xhr.responseText);
			}
		}		

		xhr.open("GET", "http://server/download/speedtest.php", true);
	 xhr.send();
	  data=xhr.responseText;
	  //alert(data);
	}
	catch(e)
	{	
		alert(e);
	}
}
//To download a payload i have included a php script which reads a 40MB file and returns payload as a responseText

header('Access-Control-Allow-Origin: *');
  $filepath="/path/argo.MP4";
  $filesize =  filesize($filepath);
   $val=readfile($filepath);


    header('Cache-Control: no-cache');
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: '. $filesize);

        echo $val;
  }
?>
Posted
Comments
Abhi Ceivea 16-Nov-13 5:22am    
When i run this script i get arnd 3.5Mbps as download and 0.9Mbps as upload but when i try to check in speedtest.net im able to get arnd 4.5Mbps and 1.5Mbps.
So let me know if you ve got any answers.
Thanks
Mike Meinz 16-Nov-13 8:33am    
Speedtest.net tests raw speed. When you run your script you get application speed because of additional overhead in inefficient http protocol.
Abhi Ceivea 17-Nov-13 5:45am    
i know its not possible to remove the HTTP overhead. But instead can anything else be done through which i can test on raw data.?

1 solution

The speed depends on the server you use for the testing purpose
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900