153 |
*/ |
*/ |
154 |
public DatagramSocket(int port, InetAddress laddr) throws SocketException |
public DatagramSocket(int port, InetAddress laddr) throws SocketException |
155 |
{ |
{ |
156 |
this (new InetSocketAddress (laddr != null ? laddr : InetAddress.ANY_IF, port)); |
if (port < 0 || port > 65535) |
157 |
} |
throw new IllegalArgumentException("Invalid port: " + port); |
|
|
|
|
/** |
|
|
* Initializes a new instance of <code>DatagramSocket</code> that binds to |
|
|
* the specified local port and address. |
|
|
* |
|
|
* @param port The local port number to bind to. |
|
|
* @param laddr The local address to bind to. |
|
|
* |
|
|
* @exception SecurityException If a security manager exists and its |
|
|
* checkListen method doesn't allow the operation. |
|
|
* @exception SocketException If an error occurs. |
|
|
* |
|
|
* @since 1.4 |
|
|
*/ |
|
|
public DatagramSocket (SocketAddress address) throws SocketException |
|
|
{ |
|
|
InetSocketAddress tmp = (InetSocketAddress) address; |
|
158 |
|
|
159 |
SecurityManager s = System.getSecurityManager(); |
SecurityManager s = System.getSecurityManager(); |
160 |
if (s != null) |
if (s != null) |
161 |
s.checkListen(tmp.getPort ()); |
s.checkListen(port); |
162 |
|
|
163 |
// Why is there no factory for this? |
// Why is there no factory for this? |
164 |
impl = new PlainDatagramSocketImpl(); |
impl = new PlainDatagramSocketImpl(); |
165 |
impl.create(); |
impl.create(); |
166 |
|
|
167 |
if (address != null) |
if (laddr != null) |
168 |
{ |
{ |
169 |
try |
try |
170 |
{ |
{ |
171 |
local_addr = tmp.getAddress (); |
local_addr = laddr; |
172 |
impl.bind(tmp.getPort (), tmp.getAddress ()); |
impl.bind(port, laddr); |
173 |
} |
} |
174 |
catch (SocketException exception) |
catch (SocketException exception) |
175 |
{ |
{ |
188 |
} |
} |
189 |
} |
} |
190 |
} |
} |
191 |
|
|
192 |
|
/** |
193 |
|
* Initializes a new instance of <code>DatagramSocket</code> that binds to |
194 |
|
* the specified local port and address. |
195 |
|
* |
196 |
|
* @param port The local port number to bind to. |
197 |
|
* @param laddr The local address to bind to. |
198 |
|
* |
199 |
|
* @exception SecurityException If a security manager exists and its |
200 |
|
* checkListen method doesn't allow the operation. |
201 |
|
* @exception SocketException If an error occurs. |
202 |
|
* |
203 |
|
* @since 1.4 |
204 |
|
*/ |
205 |
|
public DatagramSocket (SocketAddress address) throws SocketException |
206 |
|
{ |
207 |
|
this (((InetSocketAddress) address).getPort (), |
208 |
|
((InetSocketAddress) address).getAddress ()); |
209 |
|
} |
210 |
|
|
211 |
/** |
/** |
212 |
* Closes this datagram socket. |
* Closes this datagram socket. |
302 |
if (timeout instanceof Integer) |
if (timeout instanceof Integer) |
303 |
return ((Integer)timeout).intValue(); |
return ((Integer)timeout).intValue(); |
304 |
else |
else |
305 |
throw new SocketException("Internal Error"); |
return 0; |
306 |
} |
} |
307 |
|
|
308 |
/** |
/** |
406 |
*/ |
*/ |
407 |
public void setReceiveBufferSize(int size) throws SocketException |
public void setReceiveBufferSize(int size) throws SocketException |
408 |
{ |
{ |
409 |
|
if (impl == null) |
410 |
|
throw new SocketException ("Cannot initialize Socket implementation"); |
411 |
|
|
412 |
if (size < 0) |
if (size < 0) |
413 |
throw new IllegalArgumentException("Buffer size is less than 0"); |
throw new IllegalArgumentException("Buffer size is less than 0"); |
414 |
|
|
443 |
if (sm != null) |
if (sm != null) |
444 |
sm.checkConnect(address.getHostName(), port); |
sm.checkConnect(address.getHostName(), port); |
445 |
|
|
446 |
this.remoteAddress = address; |
try |
447 |
this.remotePort = port; |
{ |
448 |
|
impl.connect (address, port); |
449 |
/* FIXME: Shit, we can't do this even though the OS supports it since this |
remoteAddress = address; |
450 |
method isn't in DatagramSocketImpl. */ |
remotePort = port; |
451 |
// impl.connect(address, port); |
} |
452 |
} |
catch (SocketException e) |
453 |
|
{ |
454 |
|
// This means simply not connected or connect not implemented. |
455 |
|
} |
456 |
|
} |
457 |
|
|
458 |
/** |
/** |
459 |
* This method disconnects this socket from the address/port it was |
* This method disconnects this socket from the address/port it was |
464 |
*/ |
*/ |
465 |
public void disconnect() |
public void disconnect() |
466 |
{ |
{ |
467 |
// FIXME: See my comments on connect() |
impl.disconnect(); |
468 |
this.remoteAddress = null; |
remoteAddress = null; |
469 |
this.remotePort = -1; |
remotePort = -1; |
470 |
} |
} |
471 |
|
|
472 |
/** |
/** |