java.lang.Object | |
↳ | java.net.DatagramPacket |
This class represents a datagram packet which contains data either to be sent
or received through a DatagramSocket
. It holds additional information
such as its source or destination host.
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
DatagramPacket object to receive data up to
length bytes. | |||||||||||
Constructs a new
DatagramPacket object to receive data up to
length bytes with a specified buffer offset. | |||||||||||
Constructs a new
DatagramPacket object to send data to the port
aPort of the address host . | |||||||||||
Constructs a new
DatagramPacket object to send data to the port
aPort of the address host . | |||||||||||
Constructs a new
DatagramPacket object to send data to the
address sockAddr . | |||||||||||
Constructs a new
DatagramPacket object to send data to the
address sockAddr . |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the sender or destination IP address of this datagram packet.
| |||||||||||
Gets the data of this datagram packet.
| |||||||||||
Gets the length of the data stored in this datagram packet.
| |||||||||||
Gets the offset of the data stored in this datagram packet.
| |||||||||||
Gets the port number of the target or sender host of this datagram
packet.
| |||||||||||
Gets the host address and the port to which this datagram packet is sent
as a
SocketAddress object. | |||||||||||
Sets the IP address of the target host.
| |||||||||||
Sets the data buffer for this datagram packet.
| |||||||||||
Sets the data buffer for this datagram packet.
| |||||||||||
Sets the length of the datagram packet.
| |||||||||||
Sets the port number of the target host of this datagram packet.
| |||||||||||
Sets the
SocketAddress for this datagram packet. |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Constructs a new DatagramPacket
object to receive data up to
length
bytes.
data | a byte array to store the read characters. |
---|---|
length | the length of the data buffer. |
Constructs a new DatagramPacket
object to receive data up to
length
bytes with a specified buffer offset.
data | a byte array to store the read characters. |
---|---|
offset | the offset of the byte array where the bytes is written. |
length | the length of the data. |
Constructs a new DatagramPacket
object to send data to the port
aPort
of the address host
. The length
must be
lesser than or equal to the size of data
. The first length
bytes from the byte array position offset
are sent.
data | a byte array which stores the characters to be sent. |
---|---|
offset | the offset of data where to read from. |
length | the length of data. |
host | the address of the target host. |
aPort | the port of the target host. |
Constructs a new DatagramPacket
object to send data to the port
aPort
of the address host
. The length
must be
lesser than or equal to the size of data
. The first length
bytes are sent.
data | a byte array which stores the characters to be sent. |
---|---|
length | the length of data. |
host | the address of the target host. |
port | the port of the target host. |
Constructs a new DatagramPacket
object to send data to the
address sockAddr
. The length
must be lesser than or equal
to the size of data
. The first length
bytes of the data
are sent.
data | the byte array to store the data. |
---|---|
length | the length of the data. |
sockAddr | the target host address and port. |
SocketException | if an error in the underlying protocol occurs. |
---|
Constructs a new DatagramPacket
object to send data to the
address sockAddr
. The length
must be lesser than or equal
to the size of data
. The first length
bytes of the data
are sent.
data | the byte array to store the data. |
---|---|
offset | the offset of the data. |
length | the length of the data. |
sockAddr | the target host address and port. |
SocketException | if an error in the underlying protocol occurs. |
---|
Gets the sender or destination IP address of this datagram packet.
Gets the data of this datagram packet.
Gets the length of the data stored in this datagram packet.
Gets the offset of the data stored in this datagram packet.
Gets the port number of the target or sender host of this datagram packet.
Gets the host address and the port to which this datagram packet is sent
as a SocketAddress
object.
Sets the IP address of the target host.
addr | the target host address. |
---|
Sets the data buffer for this datagram packet.
buf | the buffer to store the data. |
---|---|
anOffset | the buffer offset where the data is stored. |
aLength | the length of the data to be sent or the length of buffer to store the received data. |
Sets the data buffer for this datagram packet. The length of the datagram packet is set to the buffer length.
buf | the buffer to store the data. |
---|
Sets the length of the datagram packet. This length plus the offset must be lesser than or equal to the buffer size.
len | the length of this datagram packet. |
---|
Sets the port number of the target host of this datagram packet.
aPort | the target host port number. |
---|
Sets the SocketAddress
for this datagram packet.
sockAddr | the SocketAddress of the target host. |
---|