1 19 package org.lucane.proxy; 20 21 import org.lucane.common.*; 22 23 import java.io.IOException ; 24 import java.net.ServerSocket ; 25 import java.net.Socket ; 26 import java.util.Hashtable ; 27 28 29 public class Proxy 30 { 31 private static final int DEFAULT_PORT = 5119; 32 private ServerSocket listener; 33 private Hashtable hash; 34 private boolean stop; 35 36 39 public Proxy(int port) 40 { 41 try 42 { 43 this.listener = new ServerSocket (port); 44 this.hash = new Hashtable (); 45 this.stop = false; 46 } 47 catch(Exception e) 48 { 49 e.printStackTrace(); 50 } 51 } 52 53 56 public void listen() 57 { 58 Socket client = null; 59 60 while(! this.stop) 61 { 62 try 63 { 64 client = this.listener.accept(); 65 (new ProxySlave(this, client)).start(); 66 } 67 catch(Exception e) 68 { 69 e.printStackTrace(); 70 } 71 } 72 } 73 74 80 public void register(ProxySlave ps, String s) 81 { 82 hash.put(s, ps); 83 } 84 85 91 public ProxySlave whois(String s) 92 { 93 return (ProxySlave)hash.get(s); 94 } 95 96 101 public static void main(String [] args) 102 { 103 try { 104 Logging.init("lucane.log", "ALL"); 105 } catch(IOException ioe) { 106 System.err.println("Unable to init logging, exiting."); 107 System.exit(1); 108 } 109 110 Proxy p; 111 112 if(args.length == 1) 113 p = new Proxy(Integer.parseInt(args[0])); 114 else 115 p = new Proxy(DEFAULT_PORT); 116 117 p.listen(); 118 } 119 } 120 | Popular Tags |