Name
Datagram
Synopsis
A Datagram represents a message to be sent from a sender
to a receiver. A Datagram consists of an arbitrary
sequence of bytes together with an address. Datagram
objects are created using the newDatagram() method of
the DatagramConnection class.
When preparing a Datagram for transmission, the data content
must be set using the setData() method, which requires
the data to be supplied in the form of an array of bytes, where the
offset and len arguments specify the
portion of the array that is to be used to form the message body. The maximum
permitted length of a Datagram can be obtained from the
DatagramConnection object. The data length associated with
the Datagram can be changed using the
setLength() method, but it cannot be increased beyond the
end of the buffer supplied by the setData method. The
reset() method is used to set the offset and length
values to zero. This method is often used when creating the message body
using the DataOutput interface methods.
A Datagram must have a destination address, which is
set using one of the two setAddress() methods. One variant
allows the address to be copied from another Datagram,
which is a convenient when creating a response to a received
Datagram. The other variant accepts a string of the form
datagram://host:port, where host is
the host name or IP address of the destination and port
is the destination’s port number. A Datagram
without a destination address to be sent using a
DatagramConnection in client mode ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access