Html 从浏览器 Ping
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26206979/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ping from browser
提问by Gal Gibli
I have an HTML page which I want to test a ping from. I want a user to connect to the website and in the main page he will get a result of the round trip from his computer to a specific server.
我有一个 HTML 页面,我想从中测试 ping。我希望用户连接到该网站,并在主页面中获得从他的计算机到特定服务器的往返结果。
Should I use "Ping"? I heard about something called applicable ping but it's something that I need to build myself and I don't know how.. Please help
我应该使用“Ping”吗?我听说过一种叫做适用 ping 的东西,但这是我需要自己构建的东西,但我不知道如何......请帮忙
回答by Krimson
Ping is just the measure of delay between a request and response. Though ping is realybased on ICMP as stated by Havenard, you can simulate this using HTML/JS but it will add a bit of delay because of processing in the high levels.
Ping 只是请求和响应之间延迟的度量。虽然 ping 确实是基于 ICMP 的,正如 Havenard 所说,您可以使用 HTML/JS 模拟这一点,但由于在高层处理,它会增加一点延迟。
ping-server.html
ping-server.html
(服务器端)hello
ping-client.html
ping-client.html
(客户端/在浏览器中使用 jQuery/js)<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
var ping = new Date;
$.ajax({
url: "ping-server.html",
cache:false,
success: function(output){
ping = new Date - ping;
Console.log("Ping/Latency: " + ping);
}
});
</script>
</head>
</html>
JSFiddle Demo!
JSFiddle 演示!
回答by Garrett Hale
http://jsfiddle.net/GSSCD/203/
http://jsfiddle.net/GSSCD/203/
I didn't make this. It seems to do what you're asking for, if you want to add your own server just add it to
这不是我做的。它似乎可以满足您的要求,如果您想添加自己的服务器,只需将其添加到
var komodel = new PingModel(['localhost',
'ws-bdimperio8',
'ws-bdimperio8.payformance.net',
'ws-bdimperio8.payformance.com',
'ws-bdimperio8.payspan.com',
'ws-bdimperio8/favicon.ico',
'127.0.0.1',
'unknown'
]);