GeezerVison is showing docs.oracle.com — DatagramPacket (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.net
Class DatagramPacket
-
-
Constructor Summary
Constructors
| Constructor |
Description |
DatagramPacket(byte[] buf,
int length) |
Constructs a DatagramPacket for receiving packets of
length length.
|
DatagramPacket(byte[] buf,
int length,
InetAddress address,
int port) |
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host.
|
DatagramPacket(byte[] buf,
int offset,
int length) |
Constructs a DatagramPacket for receiving packets of
length length, specifying an offset into the buffer.
|
DatagramPacket(byte[] buf,
int offset,
int length,
InetAddress address,
int port) |
Constructs a datagram packet for sending packets of length
length with offset ioffsetto the
specified port number on the specified host.
|
DatagramPacket(byte[] buf,
int offset,
int length,
SocketAddress address) |
Constructs a datagram packet for sending packets of length
length with offset ioffsetto the
specified port number on the specified host.
|
DatagramPacket(byte[] buf,
int length,
SocketAddress address) |
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host.
|
-
Method Summary
All Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
InetAddress |
getAddress() |
Returns the IP address of the machine to which this datagram is being
sent or from which the datagram was received.
|
byte[] |
getData() |
Returns the data buffer.
|
int |
getLength() |
Returns the length of the data to be sent or the length of the
data received.
|
int |
getOffset() |
Returns the offset of the data to be sent or the offset of the
data received.
|
int |
getPort() |
Returns the port number on the remote host to which this datagram is
being sent or from which the datagram was received.
|
SocketAddress |
getSocketAddress() |
Gets the SocketAddress (usually IP address + port number) of the remote
host that this packet is being sent to or is coming from.
|
void |
setAddress(InetAddress iaddr) |
Sets the IP address of the machine to which this datagram
is being sent.
|
void |
setData(byte[] buf) |
Set the data buffer for this packet.
|
void |
setData(byte[] buf,
int offset,
int length) |
Set the data buffer for this packet.
|
void |
setLength(int length) |
Set the length for this packet.
|
void |
setPort(int iport) |
Sets the port number on the remote host to which this datagram
is being sent.
|
void |
setSocketAddress(SocketAddress address) |
Sets the SocketAddress (usually IP address + port number) of the remote
host to which this datagram is being sent.
|
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
DatagramPacket
public DatagramPacket(byte[] buf,
int offset,
int length,
InetAddress address,
int port)
Constructs a datagram packet for sending packets of length
length with offset ioffsetto the
specified port number on the specified host. The
length argument must be less than or equal to
buf.length.
- Parameters:
buf - the packet data.
offset - the packet data offset.
length - the packet data length.
address - the destination address.
port - the destination port number.
- Since:
- 1.2
- See Also:
InetAddress
-
DatagramPacket
public DatagramPacket(byte[] buf,
int offset,
int length,
SocketAddress address)
Constructs a datagram packet for sending packets of length
length with offset ioffsetto the
specified port number on the specified host. The
length argument must be less than or equal to
buf.length.
- Parameters:
buf - the packet data.
offset - the packet data offset.
length - the packet data length.
address - the destination socket address.
- Throws:
IllegalArgumentException - if address type is not supported
- Since:
- 1.4
- See Also:
InetAddress
-
DatagramPacket
public DatagramPacket(byte[] buf,
int length,
InetAddress address,
int port)
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. The length argument must be less than or equal
to buf.length.
- Parameters:
buf - the packet data.
length - the packet length.
address - the destination address.
port - the destination port number.
- See Also:
InetAddress
-
DatagramPacket
public DatagramPacket(byte[] buf,
int length,
SocketAddress address)
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. The length argument must be less than or equal
to buf.length.
- Parameters:
buf - the packet data.
length - the packet length.
address - the destination address.
- Throws:
IllegalArgumentException - if address type is not supported
- Since:
- 1.4
- See Also:
InetAddress
-
Method Detail
-
setData
public void setData(byte[] buf,
int offset,
int length)
Set the data buffer for this packet. This sets the
data, length and offset of the packet.
- Parameters:
buf - the buffer to set for this packet
offset - the offset into the data
length - the length of the data
and/or the length of the buffer used to receive data
- Throws:
NullPointerException - if the argument is null
- Since:
- 1.2
- See Also:
getData(),
getOffset(),
getLength()
-
setData
public void setData(byte[] buf)
Set the data buffer for this packet. With the offset of
this DatagramPacket set to 0, and the length set to
the length of buf.
- Parameters:
buf - the buffer to set for this packet.
- Throws:
NullPointerException - if the argument is null.
- Since:
- JDK1.1
- See Also:
getLength(),
getData()
-
setLength
public void setLength(int length)
Set the length for this packet. The length of the packet is
the number of bytes from the packet's data buffer that will be
sent, or the number of bytes of the packet's data buffer that
will be used for receiving data. The length must be lesser or
equal to the offset plus the length of the packet's buffer.
- Parameters:
length - the length to set for this packet.
- Throws:
IllegalArgumentException - if the length is negative
of if the length is greater than the packet's data buffer
length.
- Since:
- JDK1.1
- See Also:
getLength(),
setData(byte[], int, int)
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|