104 |
* |
* |
105 |
* @param port The local port number to bind to |
* @param port The local port number to bind to |
106 |
* |
* |
107 |
|
* @exception SecurityException If a security manager exists and its |
108 |
|
* checkListen method doesn't allow the operation. |
109 |
* @exception SocketException If an error occurs. |
* @exception SocketException If an error occurs. |
110 |
*/ |
*/ |
111 |
public DatagramSocket(int port) throws SocketException |
public DatagramSocket(int port) throws SocketException |
120 |
* @param port The local port number to bind to |
* @param port The local port number to bind to |
121 |
* @param laddr The local address to bind to |
* @param laddr The local address to bind to |
122 |
* |
* |
123 |
|
* @exception SecurityException If a security manager exists and its |
124 |
|
* checkListen method doesn't allow the operation. |
125 |
* @exception SocketException If an error occurs |
* @exception SocketException If an error occurs |
126 |
*/ |
*/ |
127 |
public DatagramSocket(int port, InetAddress laddr) throws SocketException |
public DatagramSocket(int port, InetAddress laddr) throws SocketException |
128 |
{ |
{ |
129 |
if (port < 0 || port > 65535) |
this (new InetSocketAddress (laddr != null ? laddr : InetAddress.ANY_IF, port)); |
130 |
throw new IllegalArgumentException("Invalid port: " + port); |
} |
131 |
|
|
132 |
|
/** |
133 |
|
* Initializes a new instance of <code>DatagramSocket</code> that binds to |
134 |
|
* the specified local port and address. |
135 |
|
* |
136 |
|
* @param port The local port number to bind to |
137 |
|
* @param laddr The local address to bind to |
138 |
|
* |
139 |
|
* @exception SecurityException If a security manager exists and its |
140 |
|
* checkListen method doesn't allow the operation. |
141 |
|
* @exception SocketException If an error occurs |
142 |
|
*/ |
143 |
|
public DatagramSocket (SocketAddress address) throws SocketException |
144 |
|
{ |
145 |
|
InetSocketAddress tmp = (InetSocketAddress) address; |
146 |
|
|
147 |
SecurityManager s = System.getSecurityManager(); |
SecurityManager s = System.getSecurityManager(); |
148 |
if (s != null) |
if (s != null) |
149 |
s.checkListen(port); |
s.checkListen(tmp.getPort ()); |
150 |
|
|
151 |
// Why is there no factory for this? |
// Why is there no factory for this? |
152 |
impl = new PlainDatagramSocketImpl(); |
impl = new PlainDatagramSocketImpl(); |
|
|
|
153 |
impl.create(); |
impl.create(); |
154 |
|
|
155 |
if (laddr == null) |
if (address != null) |
156 |
laddr = InetAddress.ANY_IF; |
{ |
157 |
|
local_addr = tmp.getAddress (); |
158 |
local_addr = laddr; |
impl.bind(tmp.getPort (), tmp.getAddress ()); |
159 |
impl.bind(port, laddr); |
} |
160 |
} |
} |
161 |
|
|
162 |
/** |
/** |