A ping program in javascript?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Egil Hansen

    A ping program in javascript?

    Hi

    I'm wondering if its possible to write a javascript, that can ping a ip
    and return the average round trip time (like ping in dos/linux)?

    Regards, Egil.

  • Christopher J. Hahn

    #2
    Re: A ping program in javascript?

    Egil Hansen wrote:[color=blue]
    > Hi
    >
    > I'm wondering if its possible to write a javascript, that can ping a ip
    > and return the average round trip time (like ping in dos/linux)?
    >
    > Regards, Egil.[/color]


    Sorry, no... JS isn't capable of anything like this unless the host
    (usually a browser, but not necessarily) provides some interface to do
    it.

    Comment

    • Egil Hansen

      #3
      Re: A ping program in javascript?

      So, if I want to allow my website visitors to ping a server and get the
      round trip time, i have to use a java applet?

      Comment

      • Martin Honnen

        #4
        Re: A ping program in javascript?



        Egil Hansen wrote:
        [color=blue]
        > So, if I want to allow my website visitors to ping a server and get the
        > round trip time, i have to use a java applet?[/color]

        Not sure whether Java allows ping requests by now but an applet is with
        normal security settings only allowed to connect back to the server the
        HTML document with the applet has been loaded from.
        If you want to allow your visitors to use ping the do the ping on the
        server and simply provide an interface to your server-side program.

        --

        Martin Honnen

        Comment

        • Egil Hansen

          #5
          Re: A ping program in javascript?

          Hi Martin

          Thanks for the reply. I wasn't aware of the security issues.

          It would be easy to make it server side, but that's not really what I
          want. I want to allow the users to ping a server (gaming server), so
          they can know, how good or bad their connection to it is. Do you see
          any way doing this, so it won't be too much of a hazel for the users
          (e.g. changing security settings/giving my site special permissions)?

          PS. Thanks to Christopher as well for his initial answer.

          Comment

          • Christopher J. Hahn

            #6
            Re: A ping program in javascript?

            Egil Hansen wrote:[color=blue]
            > Hi Martin
            >
            > Thanks for the reply. I wasn't aware of the security issues.
            >
            > It would be easy to make it server side, but that's not really what I
            > want. I want to allow the users to ping a server (gaming server), so
            > they can know, how good or bad their connection to it is. Do you see
            > any way doing this, so it won't be too much of a hazel for the users
            > (e.g. changing security settings/giving my site special permissions)?
            >
            > PS. Thanks to Christopher as well for his initial answer.[/color]

            Given what Martin Honnen said (I assume he's right because I know
            nothing of Java and he's a fairly smart guy), if your game server is
            also the web server, it sounds like that would satisfy the security
            concerns and the applet would be allowed to do the ping or something
            like it.

            Now, knowing that your end goal is getting some feel for communications
            performance between the end user and the server...

            If you can't do it in Java, you might consider something *remotely*
            similar, like measuring how long it takes to download a file of known
            size from the server:
            The game server should serve, by FTP or (preferably) HTTP, say... an
            image of at least a couple hundred kilobytes. Then, on the host web
            page, you could do something like this:

            var I = new Image();
            I.onload = function () {
            T[ 1 ] = Number( new Date() );
            // now do something with T[ 1 ] - T[ 0 ]
            }

            var T = [ Number( new Date() ) ];

            I.src = 'http://gamehost.domain .tld/test_image.img? ' +
            Math.round( Math.random() * 10000 );


            The result is a two-element array T containing 0: the time just prior
            to telling it to start downloading the image and 1: the time just after
            it finished.

            So T[ 1 ] - T[ 0 ] = the number of milliseconds between those two
            times.

            It's not 100% accurate, but then... neither is ping, really. What you
            want is for the user to get a *feel* for how it'll go, right?

            Of course, you'll need to give them something to measure that against,
            so you'll want to be able to say, "this is optimal," "this is
            super-fast," "if it's this slow, don't even bother," etc.


            I'm sure some other guys here can brush up the code a bit and probably
            make it a bit more accurate or cross-compatible, but it's an idea.

            Good luck to you.

            Comment

            • Egil Hansen

              #7
              Re: A ping program in javascript?

              Hi again Christopher

              Interesting approach, but it won't work in my case, as I have no
              control over the gaming servers I would like to allow my users to ping.
              It could be totally random servers (users will be able to add servers
              to the website them self).

              Thanks though, regard, Egil.

              Comment

              • Ivan Marsh

                #8
                Re: A ping program in javascript?

                On Wed, 20 Jul 2005 04:41:16 -0700, Egil Hansen wrote:
                [color=blue]
                > Hi Martin
                >
                > Thanks for the reply. I wasn't aware of the security issues.
                >
                > It would be easy to make it server side, but that's not really what I
                > want. I want to allow the users to ping a server (gaming server), so
                > they can know, how good or bad their connection to it is. Do you see
                > any way doing this, so it won't be too much of a hazel for the users
                > (e.g. changing security settings/giving my site special permissions)?[/color]

                The server would have to ping the client... assuming the client allows
                icmp.

                --
                "Blessed is he who expects nothing, for he shall never be disappointed."
                Benjamin Franklin (I didn't know he was a Buddhist)

                Comment

                • Martin Honnen

                  #9
                  Re: A ping program in javascript?



                  Egil Hansen wrote:
                  [color=blue]
                  > I want to allow the users to ping a server (gaming server), so
                  > they can know, how good or bad their connection to it is. Do you see
                  > any way doing this, so it won't be too much of a hazel for the users
                  > (e.g. changing security settings/giving my site special permissions)?[/color]

                  No, inside the browser whether you use Java or JavaScript with normal
                  security settings you can only connect back to the server your document
                  has been loaded from.
                  Java 1.5 seems to have some ICMP support now with the method isReachable
                  of the InetAddress class but unless you sign your applet I don't think
                  there is any chance to use that method in the browser to check abritrary
                  hosts.

                  --

                  Martin Honnen

                  Comment

                  • Csaba Gabor

                    #10
                    Re: A ping program in javascript?

                    How about something like this for javascript ping times:

                    <body onload="alert(' body loaded');
                    window.startTim e=new Date();
                    var imgSrc='http://us.i1.yimg.com/us.yimg.com'+
                    '/i/us/nt/hdr/stw.gif'+
                    '?cacheBuster=' +Math.random();
                    document.getEle mentById('myPin gTest').src=img Src">
                    <IMG id=myPingTest
                    onload="var endTime=new Date();
                    alert('ping time in milliseconds: '+
                    (endTime.getMil liseconds()-
                    window.startTim e.getMillisecon ds()))">
                    </body>


                    It assumes a cooperating server, of course, plus there is additional
                    delay due to server processing. Still... it may give you a rough
                    idea. As implied by the "cacheBuste r" (which line is there solely to
                    prevent browser cacheing), I would be very wary of cacheing effects
                    both of the image and the path taken to the server.

                    Csaba Gabor from Vienna


                    Egil Hansen wrote:[color=blue]
                    > Hi
                    >
                    > I'm wondering if its possible to write a javascript, that can ping a ip
                    > and return the average round trip time (like ping in dos/linux)?
                    >
                    > Regards, Egil.[/color]

                    Comment

                    • fj

                      #11
                      Re: A ping program in javascript?


                      "Egil Hansen" <egil@dailyrush .dk> wrote in message
                      news:1121773452 .450026.142910@ g49g2000cwa.goo glegroups.com.. .[color=blue]
                      > Hi
                      >
                      > I'm wondering if its possible to write a javascript, that can ping a ip
                      > and return the average round trip time (like ping in dos/linux)?
                      >
                      > Regards, Egil.
                      >[/color]

                      Yes you can.

                      using AJAX.


                      Comment

                      • Csaba Gabor

                        #12
                        Re: A ping program in javascript?

                        Here is a revised way of pinging yahoo using javascript and iframes
                        that seems to work with Firefox (but Not IE 6) 1.0+ (Deer Park Alpha 1
                        rv.1.8b2 dated 20 Jun 2005). Pretty nifty that FF has an onload in the
                        <IFRAME ...> element.
                        Regarding my prior (post) example... Evidently .getMillisecond s is not
                        the way to go, despite Danny Goodman saying that it is equivalent to
                        ..getTime


                        <html><head><ti tle>Ping Testing</title>
                        <script type='text/javascript'>
                        function pingTime() {
                        var endTime=new Date();
                        alert('ping time in milliseconds: '+
                        (endTime.getTim e()-window.startTim e)
                        +"\nendTime: "+endTime.getTi me()
                        +"\nstartTim e: "+window.startT ime)
                        }
                        </script>
                        </head>
                        <body onload="alert(' body loaded');
                        var startTime=new Date();
                        window.startTim e=startTime.get Time()
                        var imgSrc='http://yahoo.com'+
                        '?cacheBuster=' +Math.random();
                        var iFrame=document .getElementById ('myPingTest');
                        iFrame.onload=p ingTime;
                        iFrame.src=imgS rc">
                        <IFRAME id=myPingTest>
                        </IFRAME>
                        </body>
                        </html>

                        Csaba Gabor from Vienna

                        Comment

                        • Randy Webb

                          #13
                          Re: A ping program in javascript?

                          fj said the following on 7/20/2005 2:15 PM:
                          [color=blue]
                          > "Egil Hansen" <egil@dailyrush .dk> wrote in message
                          > news:1121773452 .450026.142910@ g49g2000cwa.goo glegroups.com.. .
                          >[color=green]
                          >>Hi
                          >>
                          >>I'm wondering if its possible to write a javascript, that can ping a ip
                          >>and return the average round trip time (like ping in dos/linux)?
                          >>
                          >>Regards, Egil.
                          >>[/color]
                          >
                          >
                          > Yes you can.[/color]

                          Prove it.
                          [color=blue]
                          > using AJAX.[/color]

                          "AJAX" is less reliable than other ways of attempting to detect download
                          speed, all of which has variables to it that you do not (and can not)
                          control thereby making it impossible to determine reliably.


                          --
                          Randy
                          comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly

                          Comment

                          • VK

                            #14
                            Re

                            Egil Hansen wrote:[color=blue]
                            > Hi again Christopher
                            >
                            > Interesting approach, but it won't work in my case, as I have no
                            > control over the gaming servers I would like to allow my users to ping.
                            > It could be totally random servers (users will be able to add servers
                            > to the website them self).
                            >
                            > Thanks though, regard, Egil.[/color]

                            Besides other things, "timed download" pseudo-ping doesn't tell too
                            much about future game quality. It just show the approximate
                            responsability of the server on port 80 (HTTP)

                            It can be rather good on 80 (HTTP), dead slow on 21 (FTP) and totally
                            dead on say 12345 where the game server is running.

                            The only help would be a signed applet to emulate socket connection to
                            the game port.

                            Staying within JavaScript, you could implement a self-updating ranging
                            system on your servers' list. So each registered user could make his
                            finger up/finger down after the game. That would also help to
                            destribute the load more or less evenly between reliable servers.

                            Comment

                            • Egil Hansen

                              #15
                              Re: Re

                              Hi all

                              Just wanted to thank everyone for there input. Thanks, Egil.

                              Comment

                              Working...