Savarese.Org

example
Class Ping

java.lang.Object
  extended by 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

Nested Class Summary
static interface Ping.EchoReplyListener
           
 
Constructor Summary
Ping(int id)
           
 
Method Summary
 void close()
          Closes the raw socket opened by the constructor.
 int getRequestDataLength()
           
 int getRequestPacketLength()
           
static void main(java.lang.String[] args)
           
 long ping(java.net.InetAddress host)
          Issues a synchronous ping.
 void receive(java.net.InetAddress host)
           
 void receiveEchoReply(java.net.InetAddress host)
           
 void sendEchoRequest(java.net.InetAddress host)
           
 void setEchoReplyListener(Ping.EchoReplyListener l)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Ping

public Ping(int id)
     throws java.io.IOException
Throws:
java.io.IOException
Method Detail

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

Savarese.Org

Copyright © 2004-2007 Daniel F. Savarese. All Rights Reserved.