I read from somewhere that ICMP ping cannot be implemented in Java.
Which means one cannot write a ping program in Java using ICMP protocol.
How true is the statement??? Even not with the latest JDK 1.2 version???
Thank you,
Peter
You can do it if you are willing to write native methods for each and
every platform you want to support.
Mike Margozzi
That is correct. The Java FAQ explains why and presents some
close alternatives. The FAQ is at
Following is what I read from
http://www.davidreilly.com/java/java_network_programming/#3.5
"Java includes support for UDP and TCP sockets. PING requires support for
the
Internet Control Message Protocol (ICMP). Your only choice (at the moment),
is to use native code, or to use java.lang.Runtime to execute an external
ping application. You won't be able to develop a 100% Pure implementation."
So is there any example on ping using the native code or java.lang.Runtime
that I can refer to???
Does using the native code or java.lang.Runtime mean that ICMP protocol
will not be used.
Thanks again,
Peter
Michael A. Margozzi wrote in message <36EAAA21...@garlic.com>...
Here is a sample code that opens a socket on port 7 and writes a string and
reads it back. The target host name is passed on command line.
import java.net.*;
public class JPing
{
private static Socket s = null;
private static BufferedWriter os = null;
private static BufferedReader is = null;
public static void main (String argv[])
{
char str[] = new char [10];
try
{
s = new Socket (argv[0], 7);
is = new BufferedReader (new InputStreamReader
(s.getInputStream()));
os = new BufferedWriter (new OutputStreamWriter
(s.getOutputStream()));
os.write ("Hello1", 0, 6); os.flush();
is.read (str, 0, 6);
System.out.println (argv[0] + " IP = " +
s.getInetAddress());
System.out.println ("Received: " + str);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
Peter <pete...@hotmail.com> wrote in message
news:36ed0...@news.cyberway.com.sg...
>Just wondering if it is possible to fake ping by using "echo" server which
>runs on well known port# 7. If the purpose is to know that the target host
>is alive, this might work.
Only if the target host is running echo on port 7, a chancy
proposition at best.
Jim