home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / internet / report.java < prev    next >
Encoding:
Java Source  |  1996-07-04  |  2.5 KB  |  78 lines

  1.  
  2. /*  Report.java by Mark D. LaDue */
  3.  
  4. /*  March 2, 1996 */
  5.  
  6. /*  Copyright (c) 1996 Mark D. LaDue
  7.     You may study, use, modify, and distribute this example for any purpose.
  8.     This example is provided WITHOUT WARRANTY either expressed or implied.  */
  9.  
  10. /*  This class allows the applet to communicate with its home. */
  11.  
  12. import java.applet.Applet;
  13. import java.awt.*;
  14. import java.io.*;
  15. import java.net.*;
  16. import java.util.Date;
  17.  
  18. public class Report {
  19.  
  20.     public String home = new String("www.math.gatech.edu");
  21.     public int port = 9000;
  22.     public String localhome = null;
  23.     public boolean debug = false;
  24.     public InetAddress localHome = null;
  25.     public String localAddress = null;
  26.     public Date rightNow;
  27.  
  28. //  Construct the class
  29.     Report(String home, int port) {
  30.         this.home = home;
  31.         this.port = port;
  32.     }
  33.  
  34.     public void communicate(String teststr, String factorstr) {
  35.         Socket socker = null;
  36.         OutputStream outerStream = null;
  37.         byte by[] = new byte[4096];
  38.         int numberbytes;
  39.         InetAddress inneraddress = null;
  40.         String response = null;
  41.         StringBuffer responsebuf = new StringBuffer();
  42. //      System.out.println("I'm up to no good");
  43.         try {
  44.             socker = new Socket(home, port);
  45.             outerStream = socker.getOutputStream();
  46.         }
  47.         catch (IOException ioe) {
  48.             if (debug)
  49.                 System.out.println("I can't open a socket to " + home);
  50.         }
  51.         try {
  52.             if (debug)
  53.                 System.out.println("Sending factoring information to" + home);
  54.             inneraddress = socker.getInetAddress();
  55.             try {
  56.                 localHome = inneraddress.getLocalHost();
  57.                 localAddress = localHome.toString();
  58.             }
  59.             catch (UnknownHostException u) {
  60.                 System.out.println("I can't get the remote host's name");
  61.             }
  62.             rightNow = new Date();
  63.             String time = rightNow.toString();
  64.             responsebuf.append(localAddress + "\t" + time + "\t" +
  65.                                teststr + "\t" + factorstr + "\n");
  66.             response = responsebuf.toString();
  67.             numberbytes = response.length();
  68.             response.getBytes(0, numberbytes, by, 0);
  69.             outerStream.write(by, 0, numberbytes);
  70.         }
  71.         catch (IOException ioe) {
  72.             if (debug)
  73.                 System.out.println("I can't talk to " + home);
  74.         }
  75.     }
  76. }
  77.  
  78.