home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIPHEFT062001.ISO / browser / nc32lyc / comm.z / java40.jar / java / net / ServerSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-15  |  3.9 KB  |  134 lines

  1. package java.net;
  2.  
  3. import java.io.FileDescriptor;
  4. import java.io.IOException;
  5. import netscape.security.PrivilegeManager;
  6.  
  7. public class ServerSocket {
  8.    protected SocketImpl impl;
  9.    private static SocketImplFactory factory;
  10.  
  11.    protected ServerSocket() throws IOException {
  12.       this.initSocketImpl();
  13.    }
  14.  
  15.    protected void setSocketImpl(SocketImpl var1) {
  16.       if (this.impl == null) {
  17.          this.impl = var1;
  18.       }
  19.  
  20.    }
  21.  
  22.    protected void initSocketImpl() {
  23.       this.setSocketImpl(this.createSocketImpl());
  24.    }
  25.  
  26.    private SocketImpl createSocketImpl() {
  27.       return (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  28.    }
  29.  
  30.    public ServerSocket(int var1) throws IOException {
  31.       this(var1, 50, (InetAddress)null);
  32.    }
  33.  
  34.    public ServerSocket(int var1, int var2) throws IOException {
  35.       this(var1, var2, (InetAddress)null);
  36.    }
  37.  
  38.    public ServerSocket(int var1, int var2, InetAddress var3) throws IOException {
  39.       this.initSocketImpl();
  40.       if (var1 >= 0 && var1 <= 65535) {
  41.          try {
  42.             SecurityManager var4 = System.getSecurityManager();
  43.             if (var4 != null) {
  44.                var4.checkListen(var1);
  45.             }
  46.  
  47.             this.impl.create(true);
  48.             if (var3 == null) {
  49.                var3 = InetAddress.anyLocalAddress;
  50.             }
  51.  
  52.             System.getSecurityManager().checkListen(var1);
  53.             this.impl.bind(var3, var1);
  54.             this.impl.listen(var2);
  55.          } catch (SecurityException var5) {
  56.             this.impl.close();
  57.             throw var5;
  58.          } catch (IOException var6) {
  59.             this.impl.close();
  60.             throw var6;
  61.          }
  62.       } else {
  63.          throw new IllegalArgumentException("Port value out of range: " + var1);
  64.       }
  65.    }
  66.  
  67.    public InetAddress getInetAddress() {
  68.       return this.impl.getInetAddress();
  69.    }
  70.  
  71.    public int getLocalPort() {
  72.       return this.impl.getLocalPort();
  73.    }
  74.  
  75.    public Socket accept() throws IOException {
  76.       Socket var1 = new Socket();
  77.       this.implAccept(var1);
  78.       return var1;
  79.    }
  80.  
  81.    protected final void implAccept(Socket var1) throws IOException {
  82.       try {
  83.          PrivilegeManager var2 = PrivilegeManager.getPrivilegeManager();
  84.          if (!var2.hasPrincipal(var1.getClass(), PrivilegeManager.getSystemPrincipal())) {
  85.             PrivilegeManager.checkPrivilegeEnabled("UniversalConnect");
  86.          }
  87.  
  88.          var1.impl.address = new InetAddress();
  89.          var1.impl.fd = new FileDescriptor();
  90.          this.impl.accept(var1.impl);
  91.          SecurityManager var3 = System.getSecurityManager();
  92.          if (var3 != null) {
  93.             var3.checkAccept(var1.getInetAddress().getHostAddress(), var1.getPort());
  94.          }
  95.       } catch (IOException var4) {
  96.          var1.close();
  97.          throw var4;
  98.       } catch (SecurityException var5) {
  99.          var1.close();
  100.          throw var5;
  101.       }
  102.    }
  103.  
  104.    public void close() throws IOException {
  105.       this.impl.close();
  106.    }
  107.  
  108.    public synchronized void setSoTimeout(int var1) throws SocketException {
  109.       this.impl.setOption(4102, new Integer(var1));
  110.    }
  111.  
  112.    public synchronized int getSoTimeout() throws IOException {
  113.       Object var1 = this.impl.getOption(4102);
  114.       return var1 instanceof Integer ? (Integer)var1 : 0;
  115.    }
  116.  
  117.    public String toString() {
  118.       return "ServerSocket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  119.    }
  120.  
  121.    public static synchronized void setSocketFactory(SocketImplFactory var0) throws IOException {
  122.       if (factory != null) {
  123.          throw new SocketException("factory already defined");
  124.       } else {
  125.          SecurityManager var1 = System.getSecurityManager();
  126.          if (var1 != null) {
  127.             var1.checkSetFactory();
  128.          }
  129.  
  130.          factory = var0;
  131.       }
  132.    }
  133. }
  134.