1

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

Samsquanch
  • 8,042
  • 12
  • 50
  • 86
Gal Gibli
  • 404
  • 1
  • 6
  • 15
  • 1
    You cannot ping from a browser. – Niels Keurentjes Oct 05 '14 at 20:38
  • 1
    What do you actually want to achieve? Are you looking to calculate the round-trip time of a connection from the client to the server? – gandaliter Oct 05 '14 at 20:41
  • The popular "ping" refers to basic ICMP comunication, you are not capable of doing that with pure HTML/JS. You will either have to use some form of TCP Ping with AJAX or rely on third-party methods like Macromedia Flash to do it. – Havenard Oct 05 '14 at 20:41

2 Answers2

3

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!

Krimson
  • 6,306
  • 9
  • 47
  • 86
1

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