1 24 25 package org.objectweb.tribe.faultdetection; 26 27 import java.io.IOException ; 28 import java.net.DatagramPacket ; 29 import java.net.DatagramSocket ; 30 import java.net.SocketException ; 31 32 import org.objectweb.tribe.common.IpAddress; 33 import org.objectweb.tribe.messages.DatagramMessage; 34 35 41 public class UDPPingThread extends Thread 42 { 43 44 IpAddress target; 45 IpAddress src; 46 int timeout; 47 boolean alive; 48 DatagramSocket socket; 49 DatagramMessage message; 50 DatagramPacket packet; 51 52 58 public UDPPingThread(IpAddress target,IpAddress src,int timeout) throws SocketException 59 { 60 super("UDP Ping Thread"); 61 this.target = target; 62 this.src = src; 63 this.timeout = timeout; 64 socket = new DatagramSocket (src.getPort()); 65 socket.setSoTimeout(timeout); 66 message = new DatagramMessage(src,target); 67 message.setContent(new String ("Iamaping").getBytes()); 68 packet = message.getDatagramPacket(); 69 } 70 71 74 public void run() 75 { 76 try 77 { 78 alive = true; 79 socket.send(packet); 80 socket.receive(packet); 82 } 83 catch (IOException e) 84 { 85 alive = false; 86 } 87 } 88 89 94 public boolean isTargetAlive() 95 { 96 return alive; 97 } 98 } 99 | Popular Tags |