home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VPage / Java.bin / CLASSES.ZIP / java / net / Socket.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-08  |  4.2 KB  |  158 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.    public Socket(String var1, int var2, boolean var3) throws IOException {
  36.       this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, var3);
  37.    }
  38.  
  39.    public Socket(InetAddress var1, int var2, boolean var3) throws IOException {
  40.       this(var1, var2, (InetAddress)null, 0, var3);
  41.    }
  42.  
  43.    private Socket(InetAddress var1, int var2, InetAddress var3, int var4, boolean var5) throws IOException {
  44.       this();
  45.       if (var2 >= 0 && var2 <= 65535) {
  46.          if (var4 >= 0 && var4 <= 65535) {
  47.             SecurityManager var6 = System.getSecurityManager();
  48.             if (var6 != null) {
  49.                var6.checkConnect(var1.getHostAddress(), var2);
  50.             }
  51.  
  52.             try {
  53.                this.impl.create(var5);
  54.                if (var3 != null || var4 > 0) {
  55.                   if (var3 == null) {
  56.                      var3 = InetAddress.anyLocalAddress;
  57.                   }
  58.  
  59.                   this.impl.bind(var3, var4);
  60.                }
  61.  
  62.                this.impl.connect(var1, var2);
  63.             } catch (SocketException var8) {
  64.                this.impl.close();
  65.                throw var8;
  66.             }
  67.          } else {
  68.             throw new IllegalArgumentException("port out range:" + var4);
  69.          }
  70.       } else {
  71.          throw new IllegalArgumentException("port out range:" + var2);
  72.       }
  73.    }
  74.  
  75.    public InetAddress getInetAddress() {
  76.       return this.impl.getInetAddress();
  77.    }
  78.  
  79.    public InetAddress getLocalAddress() {
  80.       Object var1 = null;
  81.  
  82.       try {
  83.          var3 = (InetAddress)this.impl.getOption(15);
  84.       } catch (Exception var2) {
  85.          var3 = InetAddress.anyLocalAddress;
  86.       }
  87.  
  88.       return var3;
  89.    }
  90.  
  91.    public int getPort() {
  92.       return this.impl.getPort();
  93.    }
  94.  
  95.    public int getLocalPort() {
  96.       return this.impl.getLocalPort();
  97.    }
  98.  
  99.    public InputStream getInputStream() throws IOException {
  100.       return this.impl.getInputStream();
  101.    }
  102.  
  103.    public OutputStream getOutputStream() throws IOException {
  104.       return this.impl.getOutputStream();
  105.    }
  106.  
  107.    public void setTcpNoDelay(boolean var1) throws SocketException {
  108.       this.impl.setOption(1, new Boolean(var1));
  109.    }
  110.  
  111.    public boolean getTcpNoDelay() throws SocketException {
  112.       return (Boolean)this.impl.getOption(1);
  113.    }
  114.  
  115.    public void setSoLinger(boolean var1, int var2) throws SocketException {
  116.       if (!var1) {
  117.          this.impl.setOption(128, new Boolean(var1));
  118.       } else {
  119.          this.impl.setOption(128, new Integer(var2));
  120.       }
  121.    }
  122.  
  123.    public int getSoLinger() throws SocketException {
  124.       Object var1 = this.impl.getOption(128);
  125.       return var1 instanceof Integer ? (Integer)var1 : -1;
  126.    }
  127.  
  128.    public synchronized void setSoTimeout(int var1) throws SocketException {
  129.       this.impl.setOption(4102, new Integer(var1));
  130.    }
  131.  
  132.    public synchronized int getSoTimeout() throws SocketException {
  133.       Object var1 = this.impl.getOption(4102);
  134.       return var1 instanceof Integer ? (Integer)var1 : 0;
  135.    }
  136.  
  137.    public synchronized void close() throws IOException {
  138.       this.impl.close();
  139.    }
  140.  
  141.    public String toString() {
  142.       return "Socket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
  143.    }
  144.  
  145.    public static synchronized void setSocketImplFactory(SocketImplFactory var0) throws IOException {
  146.       if (factory != null) {
  147.          throw new SocketException("factory already defined");
  148.       } else {
  149.          SecurityManager var1 = System.getSecurityManager();
  150.          if (var1 != null) {
  151.             var1.checkSetFactory();
  152.          }
  153.  
  154.          factory = var0;
  155.       }
  156.    }
  157. }
  158.