Ping from browser [duplicate]

一曲冷凌霜 提交于 2019-12-08 07:27:21

问题


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.

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


回答1:


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-server.html (Server side)
hello


ping-client.html (Client side/In the browser using 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!




回答2:


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'
]);


来源:https://stackoverflow.com/questions/26206979/ping-from-browser

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!