/* ** Objektorienteeritud programmeerimine - datagrammiklient. ** ** NB! Tegemist on õppeotstarbelise näitega, mis ei ole ** mõeldud reaalses elus kasutamiseks. ** ** @author Gunnar Kudrjavets [gk@aprote.ee] ** @version 0.1, 13.04.1999 ** @since JDK 1.0 */ import java.io.*; import java.net.*; public class HeartBeat extends java.applet.Applet { String strHost; int iPort; public void init() { strHost = getCodeBase().getHost(); iPort = Integer.parseInt(getParameter("Port")); sendMessage("Init."); } private void sendMessage(String strMessage) { try { byte[] data = new byte[strMessage.length()]; strMessage.getBytes(0, data.length, data, 0); InetAddress addr = InetAddress.getByName(strHost); DatagramPacket pack = new DatagramPacket(data, data.length, addr, iPort); DatagramSocket ds = new DatagramSocket(); ds.send(pack); ds.close(); } catch (IOException e) { System.out.println("I/O error: " + e); } } public void start() { sendMessage("Arrived."); } public void stop() { sendMessage("Departed."); } }