example
Class Ping
java.lang.Object
example.Ping
public class Ping
- extends java.lang.Object
The Ping class is a simple demo showing how you can send
ICMP echo requests and receive echo replies using raw sockets.
- Author:
- Daniel F. Savarese
|
Constructor Summary |
Ping(int id)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Ping
public Ping(int id)
throws java.io.IOException
- Throws:
java.io.IOException
setEchoReplyListener
public void setEchoReplyListener(Ping.EchoReplyListener l)
close
public void close()
throws java.io.IOException
- Closes the raw socket opened by the constructor. After calling
this method, the object cannot be used.
- Throws:
java.io.IOException
sendEchoRequest
public void sendEchoRequest(java.net.InetAddress host)
throws java.io.IOException
- Throws:
java.io.IOException
receive
public void receive(java.net.InetAddress host)
throws java.io.IOException
- Throws:
java.io.IOException
receiveEchoReply
public void receiveEchoReply(java.net.InetAddress host)
throws java.io.IOException
- Throws:
java.io.IOException
ping
public long ping(java.net.InetAddress host)
throws java.io.IOException
- Issues a synchronous ping.
- Parameters:
host - The host to ping.
- Returns:
- The round trip time in nanoseconds.
- Throws:
java.io.IOException
getRequestDataLength
public int getRequestDataLength()
- Returns:
- The number of bytes in the data portion of the ICMP ping request
packet.
getRequestPacketLength
public int getRequestPacketLength()
- Returns:
- The number of bytes in the entire IP ping request packet.
main
public static final void main(java.lang.String[] args)
throws java.lang.Exception
- Throws:
java.lang.Exception
Copyright © 2004-2007 Daniel F. Savarese. All Rights Reserved.