简体   繁体   English

浏览器的延迟/ Ping测试

[英]Latency / Ping test from Browser

I want to check ping from Browser to a Server. 我想检查从浏览器到服务器的ping操作。

Ping/Latency should not be from Server but from Client's Machine. Ping / Latency不应来自服务器,而应来自客户端的计算机。

I have seen sites like Pingtest.net so it is possible to do from Browser. 我见过像Pingtest.net这样的网站,因此可以从浏览器中进行。

Any language will do. 任何语言都可以。

The server ping can also be tested by an UDP packet other than normal shell command ping. 除了正常的shell命令ping之外,还可以通过UDP数据包测试服务器ping。

How should i proceed. 我应该如何进行。 ?

Try using XMLHTTPRequest() for javascript. 尝试将XMLHTTPRequest()用于javascript。 The objective is to make about 10 objects and place them in an array. 目标是制作约10个对象并将它们放置在数组中。 Then use onreadystatechange in each and every one of them. 然后在每一个中使用onreadystatechange。 For the function inside it, use the status 1 to start the timer and status 3 to finish the timer. 对于其中的功能,请使用状态1启动计时器,并使用状态3完成计时器。 Use the object Date() to get the times. 使用对象Date()获取时间。

That's the whole idea behind solving that. 这就是解决这个问题的全部思路。 if you need more just comment my answer and I'll try to make it more complete and "spoily". 如果您需要更多意见,请评论我的答案,我将尝试使其更完整和“变质”。


Assuming you know how to program in javascript, this is one idea for a possible solution: You first create an array where you'll insert in each position an instance of XMLHTTPRequest(). 假设您知道如何用JavaScript编程,这是一个可能的解决方案的想法:首先创建一个数组,在该数组中的每个位置插入一个XMLHTTPRequest()实例。 Then, you'll create a function that returns a function where: 然后,您将创建一个函数,该函数返回以下函数:
The outside function will save some sort of identification towards the "current" request, including a reference to the instance. 外部函数将为“当前”请求保存某种标识,包括对实例的引用。 This function is supposed to be executed right away. 该功能应该立即执行。
The inner function is supposed to be used to execute the state and know when to "start" the timer and when to "stop" the timer. 内部函数应该用于执行状态并知道何时“启动”计时器以及何时“停止”计时器。 Take care of opening the connect and sending the headers to all of 'em, wait to get the answer and finally register the times you got. 请注意打开连接并将标头发送到所有'em,等待获得答案,最后注册获得的时间。 Do some math and you get the ping. 做一些数学运算,您就会得到Ping。

That's the whole idea behind this. 这就是背后的全部想法。 Good luck! 祝好运!

<script type="text/javascript">
try {
  netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
} catch (e) {
  alert("Permission UniversalBrowserRead denied.");
}

var req = new XMLHttpRequest();
    req.open('GET', 'http://www.mozilla.org/', false);.
    req.send();
    if(req.status == 200) {
        alert(req.responseText);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM