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; } ?>
The speed depends on the server you use for the testing purpose
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)