1 24 25 package org.objectweb.tribe.faultdetection; 26 27 import java.io.IOException ; 28 import java.net.DatagramSocket ; 29 30 import org.objectweb.tribe.common.IpAddress; 31 import org.objectweb.tribe.messages.DatagramMessage; 32 33 39 public class UDPPongThread implements Runnable 40 { 41 private IpAddress src; 42 private IpAddress target; 43 private boolean quit; 44 45 51 public UDPPongThread(IpAddress src, IpAddress target) 52 { 53 super(); 54 this.src = src; 55 this.target = target; 56 } 57 58 61 public void run() 62 { 63 DatagramSocket socket = null; 64 while (!quit) 65 { 66 try 67 { 68 socket = new DatagramSocket (src.getPort()); 69 DatagramMessage message = new DatagramMessage(src, target); 70 socket.receive(message.getDatagramPacket()); 71 socket.send(message.getDatagramPacket()); 72 socket.close(); 73 } 74 catch (IOException e) 75 { 76 e.printStackTrace(); 77 if (socket != null) 78 socket.close(); 79 } 80 81 } 82 } 83 84 89 public void setQuit(boolean quit) 90 { 91 this.quit = quit; 92 } 93 } | Popular Tags |