浏览器的延迟/ Ping测试 [英] Latency / Ping test from Browser

查看:323
本文介绍了浏览器的延迟/ Ping测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Ping /延迟不应来自服务器,而应来自客户机。



我曾经见过像Pingtest.net这样的网站,所以可以从浏览器中完成。



任何语言都可以。



服务器ping也可以通过UDP数据包进行测试,而不是使用普通的shell命令ping。

我该如何处理。 ?

解决方案

尝试使用 XMLHTTPRequest() for javascript。目标是制作大约10个对象,并将它们放在一个数组中。
然后在每一个中使用onreadystatechange。对于其中的功能,使用状态1启动定时器,状态3完成定时器。使用对象Date()获取时间。

这就是解决这个问题的总体思路。如果你需要更多的只是评论我的答案,我会尽量使它更完整和欺骗。






假设你知道如何在JavaScript中编程,这是一个可能的解决方案的想法:
您首先创建一个数组,您将在每个位置插入一个XMLHTTPRequest()的实例。
然后,您将创建一个函数,返回一个函数,其中:

外部函数将为当前请求保存某种标识,包括对实例的引用。这个函数应该马上执行。

内部函数应该用来执行状态,并知道何时启动定时器以及何时停止定时器。
打开连接并发送标题给所有的人,等待得到答案,最后注册你得到的时间。做一些数学,你会得到平。



这是这个背后的整个想法。祝你好运!


I want to check ping from Browser to a Server.

Ping/Latency should not be from Server but from Client's Machine.

I have seen sites like Pingtest.net so it is possible to do from Browser.

Any language will do.

The server ping can also be tested by an UDP packet other than normal shell command ping.

How should i proceed. ?

解决方案

Try using XMLHTTPRequest() for javascript. The objective is to make about 10 objects and place them in an array. Then use onreadystatechange in each and every one of them. For the function inside it, use the status 1 to start the timer and status 3 to finish the timer. Use the object Date() to get the times.

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(). 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. Do some math and you get the ping.

That's the whole idea behind this. Good luck!

这篇关于浏览器的延迟/ Ping测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆