java.lang.Object | |
↳ | java.net.DatagramPacket |
This class represents a datagram packet.
Datagram packets are used to implement a connectionless packet delivery service. Each message is routed from one machine to another based solely on information contained within that packet. Multiple packets sent from one machine to another might be routed differently, and might arrive in any order. Packet delivery is not guaranteed.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a
DatagramPacket for receiving packets of
length length , specifying an offset into the buffer. | |||||||||||
Constructs a
DatagramPacket for receiving packets of
length length . | |||||||||||
Constructs a datagram packet for sending packets of length
length with offset ioffset to the
specified port number on the specified host. | |||||||||||
Constructs a datagram packet for sending packets of length
length with offset ioffset to the
specified port number on the specified host. | |||||||||||
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. | |||||||||||
Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns the IP address of the machine to which this datagram is being
sent or from which the datagram was received.
| |||||||||||
Returns the data buffer.
| |||||||||||
Returns the length of the data to be sent or the length of the
data received.
| |||||||||||
Returns the offset of the data to be sent or the offset of the
data received.
| |||||||||||
Returns the port number on the remote host to which this datagram is
being sent or from which the datagram was received.
| |||||||||||
Gets the SocketAddress (usually IP address + port number) of the remote
host that this packet is being sent to or is coming from.
| |||||||||||
Sets the IP address of the machine to which this datagram
is being sent.
| |||||||||||
Set the data buffer for this packet.
| |||||||||||
Set the data buffer for this packet.
| |||||||||||
Set the length for this packet.
| |||||||||||
Sets the port number on the remote host to which this datagram
is being sent.
| |||||||||||
Sets the SocketAddress (usually IP address + port number) of the remote
host to which this datagram is being sent.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Constructs a DatagramPacket
for receiving packets of
length length
, specifying an offset into the buffer.
The length
argument must be less than or equal to
buf.length
.
buf | buffer for holding the incoming datagram. |
---|---|
offset | the offset for the buffer |
length | the number of bytes to read. |
Constructs a DatagramPacket
for receiving packets of
length length
.
The length
argument must be less than or equal to
buf.length
.
buf | buffer for holding the incoming datagram. |
---|---|
length | the number of bytes to read. |
Constructs a datagram packet for sending packets of length
length
with offset ioffset
to the
specified port number on the specified host. The
length
argument must be less than or equal to
buf.length
.
buf | the packet data. |
---|---|
offset | the packet data offset. |
length | the packet data length. |
address | the destination address. |
port | the destination port number. |
Constructs a datagram packet for sending packets of length
length
with offset ioffset
to the
specified port number on the specified host. The
length
argument must be less than or equal to
buf.length
.
buf | the packet data. |
---|---|
offset | the packet data offset. |
length | the packet data length. |
address | the destination socket address. |
IllegalArgumentException | if address type is not supported |
---|---|
SocketException |
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
.
buf | the packet data. |
---|---|
length | the packet length. |
address | the destination address. |
port | the destination port number. |
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
.
buf | the packet data. |
---|---|
length | the packet length. |
address | the destination address. |
IllegalArgumentException | if address type is not supported |
---|---|
SocketException |
Returns the IP address of the machine to which this datagram is being sent or from which the datagram was received.
Returns the data buffer. The data received or the data to be sent
starts from the offset
in the buffer,
and runs for length
long.
Returns the length of the data to be sent or the length of the data received.
Returns the offset of the data to be sent or the offset of the data received.
Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received.
Gets the SocketAddress (usually IP address + port number) of the remote host that this packet is being sent to or is coming from.
SocketAddress
Sets the IP address of the machine to which this datagram is being sent.
iaddr | the InetAddress |
---|
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
.
buf | the buffer to set for this packet. |
---|
NullPointerException | if the argument is null. |
---|
Set the data buffer for this packet. This sets the data, length and offset of the packet.
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 |
NullPointerException | if the argument is null |
---|
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.
length | the length to set for this packet. |
---|
IllegalArgumentException | if the length is negative of if the length is greater than the packet's data buffer length. |
---|
Sets the port number on the remote host to which this datagram is being sent.
iport | the port number |
---|
Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.
address | the SocketAddress |
---|
IllegalArgumentException | if address is null or is a SocketAddress subclass not supported by this socket |
---|