home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / java / net / ServerSocket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  3.3 KB  |  112 lines

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