home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / NETSCAP4.06 / CP32E406.EXE / nav40.z / java40.jar / java / net / ServerSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-08-13  |  3.5 KB  |  128 lines

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