FileDocCategorySizeDatePackage
HeartBeat.javaAPI DocExample929Sat Apr 23 22:35:38 BST 2005None

HeartBeat

public class HeartBeat extends Applet

Fields Summary
String
myHost
int
myPort
Constructors Summary
Methods Summary
public voidinit()

        myHost = getCodeBase().getHost(  );
        myPort = Integer.parseInt( getParameter("myPort") );
    
private voidsendMessage(java.lang.String message)

        try {
            byte [] data = message.getBytes("UTF-8");
            InetAddress addr = InetAddress.getByName( myHost );
            DatagramPacket pack =
              new DatagramPacket( data, data.length, addr, myPort );
            DatagramSocket ds = new DatagramSocket();
            ds.send( pack );
            ds.close();
        } catch ( IOException e ) {
            System.out.println( e );  // Error creating socket
        }
    
public voidstart()

        sendMessage("Arrived");
    
public voidstop()

        sendMessage("Departed");