Makefile.am: Added URLDecoder and URLEncoder.
[gcc.git] / libjava / java / net / Socket.java
1 // Socket.java
2
3 /* Copyright (C) 1999 Cygnus Solutions
4
5 This file is part of libgcj.
6
7 This software is copyrighted work licensed under the terms of the
8 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
9 details. */
10
11 /**
12 * @author Per Bothner <bothner@cygnus.com>
13 * @date January 6, 1999.
14 */
15
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.
19 */
20
21 package java.net;
22 import java.io.*;
23
24 public class Socket
25 {
26 static SocketImplFactory factory;
27 SocketImpl impl;
28
29 protected Socket ()
30 {
31 }
32
33 protected Socket (SocketImpl impl) throws SocketException
34 {
35 this.impl = impl;
36 }
37
38 public Socket (String host, int port)
39 throws UnknownHostException, IOException
40 {
41 this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
42 SecurityManager s = System.getSecurityManager();
43 if (s != null)
44 s.checkConnect(host, port);
45 impl.create(true);
46 impl.connect(host, port);
47 }
48
49 public Socket (InetAddress address, int port)
50 throws IOException
51 {
52 this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
53 SecurityManager s = System.getSecurityManager();
54 if (s != null)
55 s.checkConnect(address.getHostName(), port);
56 impl.create(true);
57 impl.connect(address, port);
58 }
59
60 public Socket (String host, int port,
61 InetAddress localAddr, int localPort) throws IOException
62 {
63 this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
64 SecurityManager s = System.getSecurityManager();
65 if (s != null)
66 s.checkConnect(host, port);
67 impl.create(true);
68 impl.bind(localAddr, localPort);
69 impl.connect(host, port);
70 }
71
72 public Socket (InetAddress address, int port,
73 InetAddress localAddr, int localPort) throws IOException
74 {
75 this(factory == null ? new PlainSocketImpl() : factory.createSocketImpl());
76 SecurityManager s = System.getSecurityManager();
77 if (s != null)
78 s.checkConnect(address.getHostName(), port);
79 impl.create(true);
80 impl.bind(localAddr, localPort);
81 impl.connect(address, port);
82 }
83
84 /**
85 * @deprecated Use DatagramSocket instead for UDP transport.
86 */
87 public Socket (String host, int port, boolean stream) throws IOException
88 {
89 impl = factory == null ? new PlainSocketImpl()
90 : factory.createSocketImpl();
91 impl.create(stream);
92 SecurityManager s = System.getSecurityManager();
93 if (s != null)
94 s.checkConnect(host, port);
95 impl.connect(host, port);
96 }
97
98 /**
99 * @deprecated Use DatagramSocket instead for UDP transport.
100 */
101 public Socket (InetAddress host, int port, boolean stream) throws IOException
102 {
103 impl = factory == null ? new PlainSocketImpl()
104 : factory.createSocketImpl();
105 impl.create(stream);
106 SecurityManager s = System.getSecurityManager();
107 if (s != null)
108 s.checkConnect(host.getHostName(), port);
109 impl.connect(host, port);
110 }
111
112 public InetAddress getInetAddress ()
113 {
114 return impl.getInetAddress();
115 }
116
117 public InetAddress getLocalAddress ()
118 {
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");
122 }
123
124 public int getPort ()
125 {
126 return impl.getPort();
127 }
128
129 public int getLocalPort ()
130 {
131 return impl.getLocalPort();
132 }
133
134 public InputStream getInputStream () throws IOException
135 {
136 return impl.getInputStream();
137 }
138
139 public OutputStream getOutputStream () throws IOException
140 {
141 return impl.getOutputStream();
142 }
143
144 public void setTcpNoDelay (boolean on) throws SocketException
145 {
146 throw new InternalError("Socket.setTcpNoDelay not implemented");
147 }
148
149 public boolean getTcpNoDelay() throws SocketException
150 {
151 throw new InternalError("Socket.getTcpNoDelay not implemented");
152 }
153
154 public void setSoLinger(boolean on, int linger) throws SocketException
155 {
156 throw new InternalError("Socket.setSoLinger not implemented");
157 }
158
159 public int getSoLinger() throws SocketException
160 {
161 throw new InternalError("Socket.getSoLinger not implemented");
162 }
163
164 public void setSoTimeout (int timeout) throws SocketException
165 {
166 throw new InternalError("Socket.setSoTimeout not implemented");
167 }
168
169 public int getSoTimeout () throws SocketException
170 {
171 throw new InternalError("Socket.getSoTimeout not implemented");
172 }
173
174 public void setSendBufferSize (int size) throws SocketException
175 {
176 throw new InternalError("Socket.setSendBufferSize not implemented");
177 }
178
179 public int getSendBufferSize () throws SocketException
180 {
181 throw new InternalError("Socket.getSendBufferSize not implemented");
182 }
183
184 public void setReceiveBufferSize (int size) throws SocketException
185 {
186 throw new InternalError("Socket.setReceiveBufferSize not implemented");
187 }
188
189 public int getReceiveBufferSize () throws SocketException
190 {
191 throw new InternalError("Socket.getReceiveBufferSize not implemented");
192 }
193
194 public void close () throws IOException
195 {
196 impl.close();
197 }
198
199 public String toString ()
200 {
201 return impl.toString();
202 }
203
204 public static void setSocketImplFactory (SocketImplFactory fac)
205 throws IOException
206 {
207 factory = fac;
208 }
209 }