PDA

View Full Version : Java question...


Nebula
01-29-2003, 05:31 PM
I have an idea for something to code in Java, but I would like to know how (if possible) to ping a remote server. Â*I'd normally do this in PHP, since it will be serving out webpages, but I'd like the user to see the ping from the users computer to the target server, instead of MY server to the target. Â*So, I decided Java, since I'm pretty sure JavaScript can't cut it.

I read somewhere you can't do a IMCP ping in Java, because it doesn't allow raw sockets. Â*Even if you can't, I'd imagine you could do something like just start a timer, open a socket to port 80 on the server (the servers being pinged WILL have a HTTP daemon running, so don't worry about port 80 being closed), and then after the connection is opened, stop the timer, and see how many miliseconds have passed, and then close the socket without retrieving or sending any data. Â*If you have other port number suggestions, or whatever (or more importantly, suggestions on how to do this), please reply. Â*I have a pretty basic understanding of Swing, but I have no clue about any of the networking/internet sides of Java (hence why I'll be taking the advanced Java class in session 2 this year http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/wink.gif).

Thanks a bunch for any help.

Nebula
01-29-2003, 05:52 PM
I guess I should also add that this will be a java applet that is loaded over the internet, not one that you run as an EXE or through a compiler or whatever. So, installing DLLs is out of the question.

I saw a tutorial that gave you an IMCP.dll, and then you could do it through Java, loading that file. But that's useless for my situation.

descapa
01-29-2003, 07:07 PM
I am still looking but check this out:
http://www.3dcom.com/ping/PingDisplay.html
from this page:
http://www.3dcom.com/ping/Pinger.html

they say it doesn't work though...still looking though

------more----------
check this out too:
http://www.teamlinux.org.uk/saxm/projects/icmp/

-------more-------
http://java.sun.com/j2se/1.4/docs/guide/net/enhancements14.html

Nebula
02-01-2003, 05:37 PM
OK, I managed to make code that will ping a server, and return a millisecond count. Here's the source:

http://www.planet-nebula.com/pinger.java

The way I know the code works is that it used to be in the main() function, but since I wanted it to be reusable, instead of only once, I moved it into it's own function.

Again, I've never made an applet in my life (Java prog? yes. Browser applet? no.) The applet's height and width will both be 0, I just want to have the Java file in the page so I can call it from JavaScript to get a ping time.

Confused? me too. http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/laugh.gif

So, if anyone can play around with my code and find a way to make it load so that it can run in a browser (again, no visual area), and have the doPing() function callable from JavaScript. Thanks bunches ;)

GPeszek
02-02-2003, 06:13 PM
You probably need to include this:

</span><table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">import java.applet.*;
import java.awt.*;

public class pinger extends Applet{[/QUOTE]<span id='postcolor'>

to make it an applet. http://campcaen.engin.umich.edu/iB_html/non-cgi/emoticons/smile.gif