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.
Unless otherwise specified, passing a null
argument causes
a NullPointerException
to be thrown.
Methods and constructors of DatagramPacket
accept parameters
of type SocketAddress
. DatagramPacket
supports
InetSocketAddress
, and may support additional SocketAddress
sub-types.
Modifier and Type | Field and Description |
---|---|
pack-priv InetAddress | |
pack-priv byte[] | |
pack-priv int | |
pack-priv int | |
pack-priv int | |
pack-priv int |
Access | Constructor and Description |
---|---|
public | DatagramPacket(byte[]
buffer for holding the incoming datagram. buf, int the offset for the buffer offset, int the number of bytes to read. length)Constructs a |
public | DatagramPacket(byte[]
buffer for holding the incoming datagram. buf, int the number of bytes to read. length)Constructs a |
public | DatagramPacket(byte[]
the packet data. buf, int the packet data offset. offset, int the packet data length. length, InetAddress the destination address, or address, int null .the destination port number. port)Constructs a datagram packet for sending packets of length
|
public | DatagramPacket(byte[]
the packet data. buf, int the packet data offset. offset, int the packet data length. length, SocketAddress the destination socket address. address)Constructs a datagram packet for sending packets of length
|
public | DatagramPacket(byte[]
the packet data. buf, int the packet length. length, InetAddress the destination address, or address, int null .the destination port number. port)Constructs a datagram packet for sending packets of length
|
public | DatagramPacket(byte[]
the packet data. buf, int the packet length. length, SocketAddress the destination address. address)Constructs a datagram packet for sending packets of length
|
Modifier and Type | Method and Description |
---|---|
public synchronized InetAddress | Returns: the IP address of the machine to which this datagram is being sent or from which the datagram was received.Returns the IP address of the machine to which this datagram is being
sent or from which the datagram was received, or |
public synchronized byte[] | |
public synchronized int | Returns: the length of the data to be sent or the length of the data received.Returns the length of the data to be sent or the length of the data received. |
public synchronized int | Returns: the offset of the data to be sent or the offset of the data received.Returns the offset of the data to be sent or the offset of the data received. |
public synchronized int | Returns: the port number on the remote host to which this datagram is being sent or from which the datagram was received.Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received, or 0 if not set. |
public synchronized SocketAddress | Returns: theSocketAddress Returns the |
public synchronized void | setAddress(InetAddress
the iaddr)InetAddress , or null .Sets the IP address of the machine to which this datagram is being sent. |
public synchronized void | setData(byte[]
the buffer to set for this packet buf, int the offset into the data offset, int the length of the data
and/or the length of the buffer used to receive data length)Set the data buffer for this packet. |
public synchronized void | |
public synchronized void | |
public synchronized void | setPort(int
the port number iport)Sets the port number on the remote host to which this datagram is being sent. |
public synchronized void | setSocketAddress(SocketAddress
the address)SocketAddress Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent. |
address | back to summary |
---|---|
pack-priv InetAddress address |
buf | back to summary |
---|---|
pack-priv byte[] buf |
bufLength | back to summary |
---|---|
pack-priv int bufLength |
length | back to summary |
---|---|
pack-priv int length |
offset | back to summary |
---|---|
pack-priv int offset |
port | back to summary |
---|---|
pack-priv int port |
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int offset, int length) Constructs a
The
|
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int length) Constructs a
The
|
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int offset, int length, InetAddress address, int port) Constructs a datagram packet for sending packets of length
|
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int offset, int length, SocketAddress address) Constructs a datagram packet for sending packets of length
|
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int length, InetAddress address, int port) Constructs a datagram packet for sending packets of length
|
DatagramPacket | back to summary |
---|---|
public DatagramPacket(byte[] buf, int length, SocketAddress address) Constructs a datagram packet for sending packets of length
|
getAddress | back to summary |
---|---|
public synchronized InetAddress getAddress() Returns the IP address of the machine to which this datagram is being
sent or from which the datagram was received, or
|
getData | back to summary |
---|---|
public synchronized byte[] getData() Returns the data buffer. The data received or the data to be sent
starts from the
|
getLength | back to summary |
---|---|
public synchronized int getLength() Returns the length of the data to be sent or the length of the data received.
|
getOffset | back to summary |
---|---|
public synchronized int getOffset() Returns the offset of the data to be sent or the offset of the data received.
|
getPort | back to summary |
---|---|
public synchronized int getPort() Returns the port number on the remote host to which this datagram is being sent or from which the datagram was received, or 0 if not set.
|
getSocketAddress | back to summary |
---|---|
public synchronized SocketAddress getSocketAddress() Returns the
|
setAddress | back to summary |
---|---|
public synchronized void setAddress(InetAddress iaddr) Sets the IP address of the machine to which this datagram is being sent.
|
setData | back to summary |
---|---|
public synchronized 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.
|
setData | back to summary |
---|---|
public synchronized 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 |
setLength | back to summary |
---|---|
public synchronized 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
|
setPort | back to summary |
---|---|
public synchronized void setPort(int iport) Sets the port number on the remote host to which this datagram is being sent.
|
setSocketAddress | back to summary |
---|---|
public synchronized void setSocketAddress(SocketAddress address) Sets the SocketAddress (usually IP address + port number) of the remote host to which this datagram is being sent.
|