home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 49 / cda49.iso / VNULabs / BrownOrifice / BOHTTPD-0.2 / BOHTTPD.java < prev    next >
Encoding:
Java Source  |  2000-08-05  |  1.5 KB  |  70 lines

  1. import java.applet.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.net.*;
  5.  
  6. import BOSocket;
  7. import BOServerSocket;
  8. import BOURLConnection;
  9. import BOURLInputStream;
  10. import BOHTTPDConnection;
  11.  
  12. public class BOHTTPD extends Applet implements Runnable {
  13.   String path;
  14.   BOServerSocket ess;
  15.   String host, remote_host;
  16.   int port;
  17.   Thread th;
  18.  
  19.   public String origin() {
  20.     URL appletSource = getDocumentBase();
  21.     try {
  22.       InetAddress host;
  23.       host = InetAddress.getByName(appletSource.getHost());
  24.       return host.getHostName();
  25.     } catch (Exception e) { System.out.println(e); };
  26.     return "localhost";
  27.   }
  28.  
  29.   public void init() {
  30.     try {
  31.       remote_host = origin();
  32.       path = new String(getParameter("path"));
  33. System.out.println("path=" + path);
  34.       while (path.startsWith("/")) path = path.substring(1, path.length());
  35.       if (!path.endsWith("/")) path += "/";
  36.  
  37.       host = new String(getParameter("host"));
  38. System.out.println("host=" + host);
  39.       port = new Integer(getParameter("port")).intValue();
  40. System.out.println("port=" + port);
  41.       ess = new BOServerSocket(port);
  42.     } catch (Exception e) { System.out.println(e); }
  43.   }
  44.  
  45.   public void start() { 
  46.     th = new Thread(this);
  47.     th.start();
  48.   }
  49.  
  50.   //public void stop() { 
  51.   //  th.stop();
  52.   //}
  53.  
  54.   public void run() {
  55.     BOSocket client;
  56.  
  57.     try {
  58.       while (true) {
  59.     client = ess.accept_any();
  60.  
  61.         BOHTTPDConnection ff = new BOHTTPDConnection();
  62.     ff.setSock(client);
  63.     ff.setServer(this);
  64.     (new Thread(ff)).start();
  65.       }
  66.     } catch (Exception e) { System.out.println(e); }
  67.   }
  68. }
  69.   
  70.