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

  1. package java.net;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.io.OutputStream;
  6.  
  7. public class Socket {
  8.    SocketImpl impl;
  9.    private static SocketImplFactory factory;
  10.  
  11.    protected Socket() {
  12.       this.impl = (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
  13.    }
  14.  
  15.    protected Socket(SocketImpl var1) throws SocketException {
  16.       this.impl = var1;
  17.    }
  18.  
  19.    public Socket(String var1, int var2) throws UnknownHostException, IOException {
  20.       this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, true);
  21.    }
  22.  
  23.    public Socket(InetAddress var1, int var2) throws IOException {
  24.       this(var1, var2, (InetAddress)null, 0, true);
  25.    }
  26.  
  27.    public Socket(String var1, int var2, InetAddress var3, int var4) throws IOException {
  28.       this(InetAddress.getByName(var1), var2, var3, var4, true);
  29.    }
  30.  
  31.    public Socket(InetAddress var1, int var2, InetAddress var3, int var4) throws IOException {
  32.       this(var1, var2, var3, var4, true);
  33.    }
  34.  
  35.    /** @deprecated */
  36.    public Socket(String var1, int var2, boolean var3) throws IOException {
  37.       this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, var3);
  38.    }
  39.  
  40.    /** @deprecated */
  41.    public Socket(InetAddress var1, int var2, boolean var3) throws IOException {
  42.       this(var1, var2, (InetAddress)null, 0, var3);
  43.    }
  44.  
  45.    private Socket(InetAddress var1, int var2, InetAddress var3, int var4, boolean var5) throws IOException {
  46.       this();
  47.       if (var2 >= 0 && var2 <= 65535) {
  48.          if (var4 >= 0 && var4 <= 65535) {
  49.             SecurityManager var6 = System.getSecurityManager();
  50.             if (var6 != null) {
  51.                var6.checkConnect(var1.getHostAddress(), var2);
  52.             }
  53.  
  54.             try {
  55.                this.impl.create(var5);
  56.                if (var3 != null || var4 > 0) {
  57.                   if (var3 == null) {
  58.                      var3 = InetAddress.anyLocalAddress;
  59.                   }
  60.  
  61.                   this.impl.bind(var3, var4);
  62.                }
  63.  
  64.                this.impl.connect(var1, var2);
  65.             } catch (SocketException var8) {
  66.                this.impl.close();
  67.                throw var8;
  68.             }
  69.          } else {
  70.             throw new IllegalArgumentException("port out range:" + var4);
  71.          }
  72.       } else {
  73.          throw new IllegalArgumentException("port out range:" + var2);
  74.       }
  75.    }
  76.  
  77.    public InetAddress getInetAddress() {
  78.       return this.impl.getInetAddress();
  79.    }
  80.  
  81.    public InetAddress getLocalAddress() {
  82.       Object var1 = null;
  83.  
  84.       try {
  85.          var3 = (InetAddress)this.impl.getOption(15);
  86.       } catch (Exception var2) {
  87.          var3 = InetAddress.anyLocalAddress;
  88.       }
  89.  
  90.       return var3;
  91.    }
  92.  
  93.    public int getPort() {
  94.       return this.impl.getPort();
  95.    }
  96.  
  97.    public int getLocalPort() {
  98.       return this.impl.getLocalPort();
  99.    }
  100.  
  101.    public InputStream getInputStream() throws IOException {
  102.       return this.impl.getInputStream();
  103.    }
  104.  
  105.    public OutputStream getOutputStream() throws IOException {
  106.       return this.impl.getOutputStream();
  107.    }
  108.  
  109.    public void setTcpNoDelay(boolean var1) throws SocketException {
  110.       this.impl.setOption(1, new Boolean(var1));
  111.    }
  112.  
  113.    public boolean getTcpNoDelay() throws SocketException {
  114.       return (Boolean)this.impl.getOption(1);
  115.    }
  116.  
  117.    public void setSoLinger(boolean var1, int var2) throws SocketException {
  118.       if (!var1) {
  119.          this.impl.setOption(128, new Boolean(var1));
  120.       } else {
  121.          this.impl.setOption(128, new Integer(var2));
  122.       }
  123.    }
  124.  
  125.    public int getSoLinger() throws SocketException {
  126.       Object var1 = this.impl.getOption(128);
  127.       return var1 instanceof Integer ? (Integer)var1 : -1;
  128.    }
  129.  
  130.    public synchronized void setSoTimeout(int var1) throws SocketException {
  131.       this.impl.setOption(4102, new Integer(var1));
  132.    }
  133.  
  134.    public synchronized int getSoTimeout() throws SocketException {
  135.       Object var1 = this.impl.getOption(4102);
  136.       return var1 instanceof Integer ? (Integer)var1 : 0;
  137.    }
  138.  
  139.    public synchronized void close() throws IOException {
  140.       this.impl.close();
  141.    }
  142.  
  143.    public String toString() {
  144.       return "Socket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  145.    }
  146.  
  147.    public static synchronized void setSocketImplFactory(SocketImplFactory var0) throws IOException {
  148.       if (factory != null) {
  149.          throw new SocketException("factory already defined");
  150.       } else {
  151.          SecurityManager var1 = System.getSecurityManager();
  152.          if (var1 != null) {
  153.             var1.checkSetFactory();
  154.          }
  155.  
  156.          factory = var0;
  157.       }
  158.    }
  159. }
  160.