473,379 Members | 1,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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.

Jul 23 '05 #1
14 42847
Egil Hansen wrote:
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.

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.

Jul 23 '05 #2
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?

Jul 23 '05 #3


Egil Hansen wrote:
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?


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
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
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.

Jul 23 '05 #5
Egil Hansen wrote:
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.


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.

Jul 23 '05 #6
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.

Jul 23 '05 #7
On Wed, 20 Jul 2005 04:41:16 -0700, Egil Hansen wrote:
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)?


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)

Jul 23 '05 #8


Egil Hansen wrote:
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)?


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
http://JavaScript.FAQTs.com/
Jul 23 '05 #9
How about something like this for javascript ping times:

<body onload="alert('body loaded');
window.startTime=new Date();
var imgSrc='http://us.i1.yimg.com/us.yimg.com'+
'/i/us/nt/hdr/stw.gif'+
'?cacheBuster='+Math.random();
document.getElementById('myPingTest').src=imgSrc">
<IMG id=myPingTest
onload="var endTime=new Date();
alert('ping time in milliseconds: '+
(endTime.getMilliseconds()-
window.startTime.getMilliseconds()))">
</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 "cacheBuster" (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:
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.


Jul 23 '05 #10
fj

"Egil Hansen" <eg**@dailyrush.dk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.


Yes you can.

using AJAX.
Jul 23 '05 #11
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 .getMilliseconds is not
the way to go, despite Danny Goodman saying that it is equivalent to
..getTime
<html><head><title>Ping Testing</title>
<script type='text/javascript'>
function pingTime() {
var endTime=new Date();
alert('ping time in milliseconds: '+
(endTime.getTime()-window.startTime)
+"\nendTime: "+endTime.getTime()
+"\nstartTime: "+window.startTime)
}
</script>
</head>
<body onload="alert('body loaded');
var startTime=new Date();
window.startTime=startTime.getTime()
var imgSrc='http://yahoo.com'+
'?cacheBuster='+Math.random();
var iFrame=document.getElementById('myPingTest');
iFrame.onload=pingTime;
iFrame.src=imgSrc">
<IFRAME id=myPingTest>
</IFRAME>
</body>
</html>

Csaba Gabor from Vienna

Jul 23 '05 #12
fj said the following on 7/20/2005 2:15 PM:
"Egil Hansen" <eg**@dailyrush.dk> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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.
Yes you can.


Prove it.
using AJAX.


"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.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #13
VK
Egil Hansen wrote:
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.


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.

Jul 23 '05 #14
Hi all

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

Jul 25 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include...
0
by: krisan | last post by:
Hi, i am writing a program for ping operation which supports both Ipv4 and IpV6 ..first i wrote for both of them individually , but i am unable to mix them such that they support both the versions...
3
by: Rudolf | last post by:
Is there a way in VB.Net to implement ping functionality without using raw sockets? I cannot use raw sockets because it has been locked/disabled for security reasons. Thanks Rudolf
8
by: TKowalcz | last post by:
Hello. I have a problem. I need to make a client-server application using sockets (easy). After they communicate server store information about client (IP, and some data). Later on i need to...
7
by: Linus Cohen | last post by:
Hi all, I'm a newbie to python and programming in general, so I wanted a simple project to start off. What I'm trying to do here is write a python command-line ping program, much like the Unix and...
5
by: Sonda | last post by:
how to ping ip address from c language ?
1
by: adonis | last post by:
hello. how can i ping with a specific NIC.when my computer has more than one adapter? in IPv4. thanks.
2
by: Jason | last post by:
I would like to make a simple PING program that has the following paremeters: txtAddress - a text-box that you enter an IP address into txtinterval - a text box that allows you to enter in an...
0
bIGMOS
by: bIGMOS | last post by:
I made a GUI ping program, now Im lost on how to do the server end of it Need a simple VB 2005 express program that will listen to ping request and display something like YOU ARE BE PINGED like in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.