我正在尝试使用 USB 加密狗编写代码来检查我的 ISP 的上传和下载速度。加密狗中的服务器是 Lighttpd。
我目前的下载计划是编写一个从服务器下载文件的shell脚本(文件应该足够大)并在2秒内终止进程。然后我可以获得文件大小。我重复这个过程n次(10这里),并取平均值。从统计上讲,我相信移动平均线是最好的值。请帮忙。
还,
我的上传计划是取一个大文件(20 MB)并使用shell脚本上传(也可以使用php),并用它来测量速度。我不确定如何在这里测量上传速度。我需要弥合通信差距,设备硬件具有价值,我需要获得正确的值以显示给用户。这里需要帮助。
上传代码如下。(它是一个 javascript 文件)注意:var params 约为 350 KiB
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 && 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 && 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);
}
}