186 |
this(buf, 0, length, address, port); |
this(buf, 0, length, address, port); |
187 |
} |
} |
188 |
|
|
189 |
|
/** |
190 |
|
* Initializes a new instance of <code>DatagramPacket</code> for |
191 |
|
* transmitting packets across the network. |
192 |
|
* |
193 |
|
* @param buf A buffer containing the data to send |
194 |
|
* @param offset The offset into the buffer to start writing from. |
195 |
|
* @param length The length of the buffer (must be <= buf.length) |
196 |
|
* @param address The socket address to send to |
197 |
|
* |
198 |
|
* @exception SocketException If an error occurs |
199 |
|
* |
200 |
|
* @since 1.4 |
201 |
|
*/ |
202 |
|
public DatagramPacket(byte[] buf, int offset, int length, SocketAddress address) |
203 |
|
throws SocketException |
204 |
|
{ |
205 |
|
this(buf, offset, length, ((InetSocketAddress)address).getAddress(), |
206 |
|
((InetSocketAddress)address).getPort()); |
207 |
|
} |
208 |
|
|
209 |
|
/** |
210 |
|
* Initializes a new instance of <code>DatagramPacket</code> for |
211 |
|
* transmitting packets across the network. |
212 |
|
* |
213 |
|
* @param buf A buffer containing the data to send |
214 |
|
* @param length The length of the buffer (must be <= buf.length) |
215 |
|
* @param address The socket address to send to |
216 |
|
* |
217 |
|
* @exception SocketException If an error occurs |
218 |
|
* |
219 |
|
* @since 1.4 |
220 |
|
*/ |
221 |
|
public DatagramPacket(byte[] buf, int length, SocketAddress address) |
222 |
|
throws SocketException |
223 |
|
{ |
224 |
|
this(buf, 0, length, ((InetSocketAddress)address).getAddress(), |
225 |
|
((InetSocketAddress)address).getPort()); |
226 |
|
} |
227 |
|
|
228 |
/** |
/** |
229 |
* Returns the address that this packet is being sent to or, if it was used |
* Returns the address that this packet is being sent to or, if it was used |
230 |
* to receive a packet, the address that is was received from. If the |
* to receive a packet, the address that is was received from. If the |
316 |
port = iport; |
port = iport; |
317 |
} |
} |
318 |
|
|
319 |
|
/** |
320 |
|
* Sets the address of the remote host this package will be sent |
321 |
|
* |
322 |
|
* @param address The socket address of the remove host |
323 |
|
* |
324 |
|
* @exception IllegalArgumentException If an error occurs |
325 |
|
* |
326 |
|
* @since 1.4 |
327 |
|
*/ |
328 |
|
public void setSocketAddress(SocketAddress address) |
329 |
|
throws IllegalArgumentException |
330 |
|
{ |
331 |
|
if (address == null) throw new IllegalArgumentException(); |
332 |
|
|
333 |
|
InetSocketAddress tmp = (InetSocketAddress)address; |
334 |
|
this.address = tmp.getAddress(); |
335 |
|
this.port = tmp.getPort(); |
336 |
|
} |
337 |
|
|
338 |
|
/** |
339 |
|
* Gets the socket address of the host this packet |
340 |
|
* will be sent to/is coming from |
341 |
|
* |
342 |
|
* @return The socket address of the remote host |
343 |
|
* |
344 |
|
* @since 1.4 |
345 |
|
*/ |
346 |
|
public SocketAddress getSocketAddress() |
347 |
|
{ |
348 |
|
return new InetSocketAddress (address, port); |
349 |
|
} |
350 |
|
|
351 |
/** |
/** |
352 |
* Sets the data buffer for this packet. |
* Sets the data buffer for this packet. |
353 |
* |
* |