home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
-
- public class Socket {
- SocketImpl impl;
- private static SocketImplFactory factory;
-
- protected Socket() {
- this.impl = (SocketImpl)(factory != null ? factory.createSocketImpl() : new PlainSocketImpl());
- }
-
- protected Socket(SocketImpl var1) throws SocketException {
- this.impl = var1;
- }
-
- public Socket(String var1, int var2) throws UnknownHostException, IOException {
- this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, true);
- }
-
- public Socket(InetAddress var1, int var2) throws IOException {
- this(var1, var2, (InetAddress)null, 0, true);
- }
-
- public Socket(String var1, int var2, InetAddress var3, int var4) throws IOException {
- this(InetAddress.getByName(var1), var2, var3, var4, true);
- }
-
- public Socket(InetAddress var1, int var2, InetAddress var3, int var4) throws IOException {
- this(var1, var2, var3, var4, true);
- }
-
- /** @deprecated */
- public Socket(String var1, int var2, boolean var3) throws IOException {
- this(InetAddress.getByName(var1), var2, (InetAddress)null, 0, var3);
- }
-
- /** @deprecated */
- public Socket(InetAddress var1, int var2, boolean var3) throws IOException {
- this(var1, var2, (InetAddress)null, 0, var3);
- }
-
- private Socket(InetAddress var1, int var2, InetAddress var3, int var4, boolean var5) throws IOException {
- this();
- if (var2 >= 0 && var2 <= 65535) {
- if (var4 >= 0 && var4 <= 65535) {
- SecurityManager var6 = System.getSecurityManager();
- if (var6 != null) {
- var6.checkConnect(var1.getHostAddress(), var2);
- }
-
- try {
- this.impl.create(var5);
- if (var3 != null || var4 > 0) {
- if (var3 == null) {
- var3 = InetAddress.anyLocalAddress;
- }
-
- this.impl.bind(var3, var4);
- }
-
- this.impl.connect(var1, var2);
- } catch (SocketException var8) {
- this.impl.close();
- throw var8;
- }
- } else {
- throw new IllegalArgumentException("port out range:" + var4);
- }
- } else {
- throw new IllegalArgumentException("port out range:" + var2);
- }
- }
-
- public InetAddress getInetAddress() {
- return this.impl.getInetAddress();
- }
-
- public InetAddress getLocalAddress() {
- Object var1 = null;
-
- try {
- var3 = (InetAddress)this.impl.getOption(15);
- } catch (Exception var2) {
- var3 = InetAddress.anyLocalAddress;
- }
-
- return var3;
- }
-
- public int getPort() {
- return this.impl.getPort();
- }
-
- public int getLocalPort() {
- return this.impl.getLocalPort();
- }
-
- public InputStream getInputStream() throws IOException {
- return this.impl.getInputStream();
- }
-
- public OutputStream getOutputStream() throws IOException {
- return this.impl.getOutputStream();
- }
-
- public void setTcpNoDelay(boolean var1) throws SocketException {
- this.impl.setOption(1, new Boolean(var1));
- }
-
- public boolean getTcpNoDelay() throws SocketException {
- return (Boolean)this.impl.getOption(1);
- }
-
- public void setSoLinger(boolean var1, int var2) throws SocketException {
- if (!var1) {
- this.impl.setOption(128, new Boolean(var1));
- } else {
- this.impl.setOption(128, new Integer(var2));
- }
- }
-
- public int getSoLinger() throws SocketException {
- Object var1 = this.impl.getOption(128);
- return var1 instanceof Integer ? (Integer)var1 : -1;
- }
-
- public synchronized void setSoTimeout(int var1) throws SocketException {
- this.impl.setOption(4102, new Integer(var1));
- }
-
- public synchronized int getSoTimeout() throws SocketException {
- Object var1 = this.impl.getOption(4102);
- return var1 instanceof Integer ? (Integer)var1 : 0;
- }
-
- public synchronized void close() throws IOException {
- this.impl.close();
- }
-
- public String toString() {
- return "Socket[addr=" + this.impl.getInetAddress() + ",port=" + this.impl.getPort() + ",localport=" + this.impl.getLocalPort() + "]";
- }
-
- public static synchronized void setSocketImplFactory(SocketImplFactory var0) throws IOException {
- if (factory != null) {
- throw new SocketException("factory already defined");
- } else {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- var1.checkSetFactory();
- }
-
- factory = var0;
- }
- }
- }
-