3 /* Copyright (C) 1999 Cygnus Solutions
5 This file is part of libgcj.
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date January 6, 1999.
16 /** Written using on-line Java Platform 1.2 API Specification.
17 * Status: I believe all methods are implemented, but many
18 * of them just throw an exception.
26 static SocketImplFactory factory
;
33 protected Socket (SocketImpl impl
) throws SocketException
38 public Socket (String host
, int port
)
39 throws UnknownHostException
, IOException
41 this(factory
== null ?
new PlainSocketImpl() : factory
.createSocketImpl());
42 SecurityManager s
= System
.getSecurityManager();
44 s
.checkConnect(host
, port
);
46 impl
.connect(host
, port
);
49 public Socket (InetAddress address
, int port
)
52 this(factory
== null ?
new PlainSocketImpl() : factory
.createSocketImpl());
53 SecurityManager s
= System
.getSecurityManager();
55 s
.checkConnect(address
.getHostName(), port
);
57 impl
.connect(address
, port
);
60 public Socket (String host
, int port
,
61 InetAddress localAddr
, int localPort
) throws IOException
63 this(factory
== null ?
new PlainSocketImpl() : factory
.createSocketImpl());
64 SecurityManager s
= System
.getSecurityManager();
66 s
.checkConnect(host
, port
);
68 impl
.bind(localAddr
, localPort
);
69 impl
.connect(host
, port
);
72 public Socket (InetAddress address
, int port
,
73 InetAddress localAddr
, int localPort
) throws IOException
75 this(factory
== null ?
new PlainSocketImpl() : factory
.createSocketImpl());
76 SecurityManager s
= System
.getSecurityManager();
78 s
.checkConnect(address
.getHostName(), port
);
80 impl
.bind(localAddr
, localPort
);
81 impl
.connect(address
, port
);
85 * @deprecated Use DatagramSocket instead for UDP transport.
87 public Socket (String host
, int port
, boolean stream
) throws IOException
89 impl
= factory
== null ?
new PlainSocketImpl()
90 : factory
.createSocketImpl();
92 SecurityManager s
= System
.getSecurityManager();
94 s
.checkConnect(host
, port
);
95 impl
.connect(host
, port
);
99 * @deprecated Use DatagramSocket instead for UDP transport.
101 public Socket (InetAddress host
, int port
, boolean stream
) throws IOException
103 impl
= factory
== null ?
new PlainSocketImpl()
104 : factory
.createSocketImpl();
106 SecurityManager s
= System
.getSecurityManager();
108 s
.checkConnect(host
.getHostName(), port
);
109 impl
.connect(host
, port
);
112 public InetAddress
getInetAddress ()
114 return impl
.getInetAddress();
117 public InetAddress
getLocalAddress ()
119 // There doesn't seem to be any way to implement this
120 // using a (generic) SocketImpl ... What am I missing?
121 throw new InternalError("Socket.getLocalAddres not implemented");
124 public int getPort ()
126 return impl
.getPort();
129 public int getLocalPort ()
131 return impl
.getLocalPort();
134 public InputStream
getInputStream () throws IOException
136 return impl
.getInputStream();
139 public OutputStream
getOutputStream () throws IOException
141 return impl
.getOutputStream();
144 public void setTcpNoDelay (boolean on
) throws SocketException
146 throw new InternalError("Socket.setTcpNoDelay not implemented");
149 public boolean getTcpNoDelay() throws SocketException
151 throw new InternalError("Socket.getTcpNoDelay not implemented");
154 public void setSoLinger(boolean on
, int linger
) throws SocketException
156 throw new InternalError("Socket.setSoLinger not implemented");
159 public boolean getSoLinger() throws SocketException
161 throw new InternalError("Socket.getSoLinger not implemented");
164 public void setSoTimeout (int timeout
) throws SocketException
166 throw new InternalError("Socket.setSoTimeout not implemented");
169 public int getSoTimeout () throws SocketException
171 throw new InternalError("Socket.getSoTimeout not implemented");
174 public void setSendBufferSize (int size
) throws SocketException
176 throw new InternalError("Socket.setSendBufferSize not implemented");
179 public int getSendBufferSize () throws SocketException
181 throw new InternalError("Socket.getSendBufferSize not implemented");
184 public void setReceiveBufferSize (int size
) throws SocketException
186 throw new InternalError("Socket.setReceiveBufferSize not implemented");
189 public int getReceiveBufferSize () throws SocketException
191 throw new InternalError("Socket.getReceiveBufferSize not implemented");
194 public void close () throws IOException
199 public String
toString ()
201 return impl
.toString();
204 public static void setSocketImplFactory (SocketImplFactory fac
)