[英]How do you send and receive the same image between the client and the server?
I'm trying to implement a bandwidth test, and it looks like the most conventional way to do this is basically to transmit one or more images back and forth between a client and a server and see what the upload and download times are. 我正在尝试实施带宽测试,看起来最常规的方法是在客户端和服务器之间来回传输一个或多个图像,看看上传和下载时间是多少。 In fact, this answer already covers the idea of getting a download time.
事实上, 这个答案已经涵盖了获取下载时间的想法。
At this point though, I'm not too sure how to make the process go both ways, with or without using the other answer . 但是,在这一点上,我不太确定如何使用或不使用其他答案来使流程双向进行 。 Even after adding debugging statements, I haven't found where the picture's data is stored in the other answer's code.
即使在添加调试语句之后,我还没有找到图片数据存储在其他答案代码中的位置。 And if I try to start off with a clean slate, a lot of the API information I'm finding on the Internet / Stack Overflow about sending images back and forth has very little explanation or elaboration, so I'm not able to use it put the two together.
如果我尝试从一个干净的平板开始,我在Internet / Stack Overflow上发现的很多关于来回发送图像的API信息几乎没有解释或详细说明,所以我无法使用它把两者放在一起。 Furthermore some experiments I have put together that have sometimes involved other platforms seemed to really throttle bandwidth usage, as well as scale the delay improperly with the images' sizes.
此外,我将有时涉及其他平台的一些实验放在一起似乎真正限制了带宽使用,以及根据图像的大小不正确地缩放延迟。
Using JavaScript, how do you transmit the same image back and forth between the client and server in such a way that you can accurately use the delay and the image's size to measure bandwidth? 使用JavaScript,您如何在客户端和服务器之间来回传输相同的图像,以便您可以准确地使用延迟和图像的大小来测量带宽? How do you make this work both ways with the same image, without throttling, and without interaction from the user?
如何使用相同的图像,无需限制,并且没有用户的交互,这两种方式都可以工作?
EDIT 编辑
I could try posting things I've tried, but it's hard for it to be meaningful. 我可以尝试发布我尝试过的东西,但它很难有意义。 A lot of it was in Flash.
其中很多都是在Flash中。 When I start using JavaScript, I started to experiment a little along these lines:
当我开始使用JavaScript时,我开始尝试这些方面:
$.get('http://ip address/test.php?filename=XXX&data=LONG STRING OF DATA REPRESTING THE DATA TO BE SAVED PROBABLY LESS THAN 2K IN SIZE AND ALSO YOU SHOULD ESCAPE OR ATLEAST URIENCODE IT', function(data) {
alert('here')
eval(data);
});
The PHP file being: PHP文件是:
<?php
echo "response=here";
?>
And I used the PHP file both for Flash and for JavaScript. 我将PHP文件用于Flash和JavaScript。 I also used Adobe Media Server with Flash.
我还使用Adobe Media Server和Flash。 But going from a 1MB file to a 32MB file while using Flash/PHP, Flash would only scale the delay by 10 times, nowhere near 32. It also seemed to throttle bandwidth usage at least when paired with the AMS, and maybe even when it was paired with the PHP file.
但是在使用Flash / PHP时,从1MB文件到32MB文件,Flash只会将延迟缩放10倍,远不及32。它似乎也至少在与AMS配对时限制带宽使用,甚至可能与PHP文件配对。
I was about to convert the JavaScript code to pass the actual image in to the PHP file...but I can't get to it. 我即将转换JavaScript代码以将实际图像传递到PHP文件...但我无法达到它。 Even when I do things like:
即使我做的事情如下:
for (var s in download) {
alert(s + ": " + download[s]);
}
download
being the object that downloaded the image in the JavaScript (see the linked answer for the code), I'm not seeing anything useful. download
是在JavaScript中下载图像的对象(请参阅链接的代码答案),我没有看到任何有用的东西。 download.children.length
is 0 and so on. download.children.length
为0,依此类推。 I'm also reluctant to trust that the results aren't throttling bandwidth usage, like the Flash experiments did, without further confirmation; 我也不愿意相信结果不会限制带宽使用,就像Flash实验那样,没有进一步的确认; maybe the image has to be passed in using one type of API call or another to get it to really work right?
也许图像必须使用一种类型的API调用或其他类型来传递,以使其真正正常工作?
In essence, I'm really looking for good API information. 从本质上讲,我真的在寻找好的API信息。 Other stuff I saw just wasn't elaborate enough to connect the dots with.
我看到的其他东西并不精确,无法连接点。
2ND EDIT 2ND编辑
One of the pitfalls I've run into is using POST to download the images. 我遇到的一个陷阱是使用POST来下载图像。 I'm running into a lot of difficulty in getting IIS 7 to allow POST to download arbitrary file types (namely jpgs) with "unusual" binary characters and allow them to be more than 2MB in size.
我在使IIS 7允许POST下载具有 “异常”二进制字符的任意文件类型(即jpgs) 并允许它们大小超过2MB时遇到了很多困难。
Why don't you send some text using $.post. 为什么不使用$ .post发送一些文本。 Eg: Generate some big text:
例如:生成一些大文本:
var someText = '0123456789';
for (var i = 0; i <= 10000; i++)
{
someText += someText;
}
then post it to the server: 然后将其发布到服务器:
var start = new Date();
$.post('yourUrl', {data:someText}, function(){
var end = new Date();
//this will show the bytes per second upload bandwidth
alert(someText.length / ((end - start)/1000));
});
To be sure the result is exact, you can run this, for example, 10 times and get the average value. 为了确保结果是准确的,你可以运行它,例如,10次并获得平均值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.