Java Reference
In-Depth Information
remoteAddr
Address (typically destination) of the datagram
remotePort
Port (typically destination) of the datagram
Accessors/Mutators
InetAddress
getAddress
()
void
setAddress
(
InetAddress
address
)
Returns/sets the datagram address. There are other ways to set the address: 1) the
address of a
DatagramPacket
instance can also be set by the constructor, and 2)
the
receive()
method of
DatagramSocket
sets the address to the datagram sender's
address.
address
Datagram address
int
getPort
()
void
setPort
(
int
port
)
Returns/sets the datagram port. There are other ways to set the address: 1) the port
can be explicitly set by the constructor or the
setPort()
method, and 2) the
receive()
method of
DatagramSocket
sets the port to the datagram sender's port.
port
Datagram port
int
getLength
()
void
setLength
(
int
length
)
Returns/sets the internal length of the datagram. The internal datagram length can be
set explicitly by the constructor or by the
setLength()
method. Attempting to make it
larger than the length of the associated buffer results in an
IllegalArgumentException
.
The
receive()
method of
DatagramSocket
uses the internal length in two ways: 1) on
input, it specifies the maximum number of bytes of a received message that will be
copied into the buffer, and 2) on return, it indicates the number of bytes actually placed
in the buffer.
length
Length in bytes of the usable portion of the buffer
int
getOffset
()
Returns the location in the buffer of the first byte of data to be sent/received. There
is no
setOffset()
method; however, it can be set with
setData()
.
byte[ ]
getData
()
Returns the buffer associated with the datagram. The returned object is a reference
to the byte array that was most recently associated with this
DatagramPacket
, either
by the constructor or by
setData()
. The length of the returned buffer may be greater
than the internal datagram length, so the internal length and offset values should be
used to determine the actual received data.
Search WWH ::
Custom Search