import java.applet.*; import java.net.*; import java.io.*; import java.util.*; import java.awt.*; public class ReloadApplet extends Applet implements Runnable { static long last_reload = 0; Thread reload_thread; private long getLastModified () { URL doc_url = getDocumentBase (); Socket s = null; DataInputStream in; PrintStream out; String line; long last_modified = 0; try { s = new Socket (doc_url.getHost (), doc_url.getPort ()); in = new DataInputStream (s.getInputStream ()); out = new PrintStream (s.getOutputStream ()); out.println ("HEAD " + doc_url.getFile () + " HTTP/1.0"); out.println (""); out.flush (); while (true) { if ((line = in.readLine ()) == null) break; if (line.substring (0, 15).equalsIgnoreCase ("last-modified: ")) { last_modified = Date.parse (line.substring (15)); break; } } } catch (IOException e) { System.out.println (e.toString ()); } finally { if (s != null) s.close (); } return last_modified; } public void run () { while (true) { try { Thread.sleep (10000); } catch (InterruptedException e) {} if (getLastModified () > last_reload) getAppletContext ().showDocument (getDocumentBase ()); } } public void start () { last_reload = getLastModified (); reload_thread = new Thread (this); reload_thread.start (); } public void stop () { reload_thread.stop (); } public void addNotify () {} public void show () {} }