import java.applet.*; import java.net.*; import java.io.*; import java.awt.*; public class watasi extends Applet implements Runnable { String host = "www2s.biglobe.ne.jp"; // ホスト名を設定する String cgi = "/~cru/library/java/cgi-bin/watasi.cgi"; // cgiを設置したpathを設定する int port = 80; Thread th; String str; int x, y; public void start() { th = new Thread( this ); th.start(); } public void run() { x = 20; y = 20; str = "Wait !"; setBackground( new Color( 0x99, 0xcc, 0xcc ) ); repaint(); try { Socket sock = new Socket( host, port ); str = "nuking "; repaint(); DataInputStream dis = new DataInputStream( sock.getInputStream() ); PrintStream ps = new PrintStream( sock.getOutputStream() ); ps.print( "GET " + cgi + " HTTP/1.0\r\n\r\n" ); str += ". "; repaint(); String s = null; while ( null != (s = dis.readLine()) ) { if ( s.equals( "" ) ) break; str += ". "; repaint(); } str = dis.readLine(); sock.close(); if ( str.substring(0,1).equalsIgnoreCase("<") ) { str = "ERROR: Please retry !"; } x = 200; y = 50; repaint(); } catch (UnknownHostException e) { str = "ERROR: fatal error !"; } catch (IOException e) { try { URL url = new URL( "http://" + host + cgi + "?ERROR: socket error !" ); DataInputStream dis = new DataInputStream( url.openStream() ); String s; while ( null != (s = dis.readLine()) ) { str = s; } if ( str.substring(0,1).equalsIgnoreCase("<") ) { str = "ERROR: Please retry !"; } x = 200; y = 50; repaint(); } catch (UnknownHostException ee) { } catch (IOException ee) { } } } public void paint( Graphics g ) { g.drawString( str, x, y ); } public void stop() { th.stop(); th = null; } }