Starting and Stopping Applets

Five methods are essential in every applet:


Below is (most of) the source code for a small applet that notifies a WWW server when the user leaves a page:
public class Stop extends Applet {

    URL stopURL = null;
    String host = null;

    public void init() {
        try {
            stopURL = new URL(getParameter("STOPURL"));
            host = getParameter("host");
        } catch (MalformedURLException e) { ; }
    }

    public void start() { }

    public void stop() {
        Socket s = null;
        try {
            s = new Socket(host, 80);
            PrintStream server_out = new PrintStream(s.getOutputStream());
            server_out.println("GET " + getParameter("STOPURL") + " HTTP/1.0");
            server_out.println(""); server_out.println("");
        } catch (IOException e) { System.out.println(e); }
        finally {
            try { if (s != null) s.close(); }
            catch (IOException e2) { ; }
        }
    }
}