home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-08-05 | 1.5 KB | 70 lines |
- import java.applet.*;
- import java.lang.*;
- import java.io.*;
- import java.net.*;
-
- import BOSocket;
- import BOServerSocket;
- import BOURLConnection;
- import BOURLInputStream;
- import BOHTTPDConnection;
-
- public class BOHTTPD extends Applet implements Runnable {
- String path;
- BOServerSocket ess;
- String host, remote_host;
- int port;
- Thread th;
-
- public String origin() {
- URL appletSource = getDocumentBase();
- try {
- InetAddress host;
- host = InetAddress.getByName(appletSource.getHost());
- return host.getHostName();
- } catch (Exception e) { System.out.println(e); };
- return "localhost";
- }
-
- public void init() {
- try {
- remote_host = origin();
- path = new String(getParameter("path"));
- System.out.println("path=" + path);
- while (path.startsWith("/")) path = path.substring(1, path.length());
- if (!path.endsWith("/")) path += "/";
-
- host = new String(getParameter("host"));
- System.out.println("host=" + host);
- port = new Integer(getParameter("port")).intValue();
- System.out.println("port=" + port);
- ess = new BOServerSocket(port);
- } catch (Exception e) { System.out.println(e); }
- }
-
- public void start() {
- th = new Thread(this);
- th.start();
- }
-
- //public void stop() {
- // th.stop();
- //}
-
- public void run() {
- BOSocket client;
-
- try {
- while (true) {
- client = ess.accept_any();
-
- BOHTTPDConnection ff = new BOHTTPDConnection();
- ff.setSock(client);
- ff.setServer(this);
- (new Thread(ff)).start();
- }
- } catch (Exception e) { System.out.println(e); }
- }
- }
-
-