FileDocCategorySizeDatePackage
HeartBeat.javaAPI DocExample927Mon May 01 14:41:46 BST 2000None

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(  );
            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");