| java.lang.Object java.net.DatagramPacket
DatagramPacket | final public class DatagramPacket (Code) | | 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.
author: Pavani Diwanji author: Benjamin Renaud version: 1.30, 02/02/00 since: JDK1.0 |
Constructor Summary | |
public | DatagramPacket(byte buf, int offset, int length) 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 . | public | DatagramPacket(byte buf, int length) Constructs a DatagramPacket for receiving packets of
length length . | public | DatagramPacket(byte buf, int offset, int length, InetAddress address, int port) Constructs a datagram packet for sending packets of length
length with offset ioffset to the
specified port number on the specified host. | public | DatagramPacket(byte buf, int offset, int length, SocketAddress address) Constructs a datagram packet for sending packets of length
length with offset ioffset to the
specified port number on the specified host. | public | DatagramPacket(byte buf, int length, InetAddress address, int port) Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. | public | DatagramPacket(byte buf, int length, SocketAddress address) Constructs a datagram packet for sending packets of length
length to the specified port number on the specified
host. |
Method 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. | public synchronized byte[] | getData() Returns the data buffer. | public synchronized int | getLength() Returns the length of the data to be sent or the length of the
data received. | public synchronized int | getOffset() Returns the offset of the data to be sent or the offset of the
data received. | 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. | public synchronized SocketAddress | getSocketAddress() Gets the SocketAddress (usually IP address + port number) of the remote
host that this packet is being sent to or is coming from. | public synchronized void | setAddress(InetAddress iaddr) Sets the IP address of the machine to which this datagram
is being sent. | public synchronized void | setData(byte[] buf, int offset, int length) Set the data buffer for this packet. | public synchronized void | setData(byte[] buf) Set the data buffer for this packet. | public synchronized void | setLength(int length) Set the length for this packet. | public synchronized void | setPort(int iport) Sets the port number on the remote host to which this datagram
is being sent. | 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. |
DatagramPacket | public DatagramPacket(byte buf, int offset, int length)(Code) | | 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 .
Parameters: buf - buffer for holding the incoming datagram. Parameters: offset - the offset for the buffer Parameters: length - the number of bytes to read. since: JDK1.2 |
DatagramPacket | public DatagramPacket(byte buf, int length)(Code) | | Constructs a DatagramPacket for receiving packets of
length length .
The length argument must be less than or equal to
buf.length .
Parameters: buf - buffer for holding the incoming datagram. Parameters: length - the number of bytes to read. |
DatagramPacket | public DatagramPacket(byte buf, int offset, int length, InetAddress address, int port)(Code) | | 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 .
Parameters: buf - the packet data. Parameters: offset - the packet data offset. Parameters: length - the packet data length. Parameters: address - the destination address. Parameters: port - the destination port number. See Also: java.net.InetAddress since: JDK1.2 |
DatagramPacket | public DatagramPacket(byte buf, int offset, int length, SocketAddress address) throws SocketException(Code) | | 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 .
Parameters: buf - the packet data. Parameters: offset - the packet data offset. Parameters: length - the packet data length. Parameters: address - the destination socket address. throws: IllegalArgumentException - if address type is not supported See Also: java.net.InetAddress since: 1.4 |
DatagramPacket | public DatagramPacket(byte buf, int length, InetAddress address, int port)(Code) | | 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 .
Parameters: buf - the packet data. Parameters: length - the packet length. Parameters: address - the destination address. Parameters: port - the destination port number. See Also: java.net.InetAddress |
DatagramPacket | public DatagramPacket(byte buf, int length, SocketAddress address) throws SocketException(Code) | | 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 .
Parameters: buf - the packet data. Parameters: length - the packet length. Parameters: address - the destination address. throws: IllegalArgumentException - if address type is not supported since: 1.4 See Also: java.net.InetAddress |
getData | public synchronized byte[] getData()(Code) | | 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.
the buffer used to receive or send data See Also: DatagramPacket.setData(byte[],int,int) |
getLength | public synchronized int getLength()(Code) | | Returns the length of the data to be sent or the length of the
data received.
the length of the data to be sent or the length of thedata received. See Also: DatagramPacket.setLength(int) |
getOffset | public synchronized int getOffset()(Code) | | Returns the offset of the data to be sent or the offset of the
data received.
the offset of the data to be sent or the offset of thedata received. since: JDK1.2 |
getPort | public synchronized int getPort()(Code) | | Returns the port number on the remote host to which this datagram is
being sent or from which the datagram was received.
the port number on the remote host to which this datagram isbeing sent or from which the datagram was received. See Also: DatagramPacket.setPort(int) |
getSocketAddress | public synchronized SocketAddress getSocketAddress()(Code) | | Gets the SocketAddress (usually IP address + port number) of the remote
host that this packet is being sent to or is coming from.
the SocketAddress since: 1.4 See Also: DatagramPacket.setSocketAddress |
setAddress | public synchronized void setAddress(InetAddress iaddr)(Code) | | Sets the IP address of the machine to which this datagram
is being sent.
Parameters: iaddr - the InetAddress since: JDK1.1 See Also: DatagramPacket.getAddress() |
setData | public synchronized void setData(byte[] buf, int offset, int length)(Code) | | Set the data buffer for this packet. This sets the
data, length and offset of the packet.
Parameters: buf - the buffer to set for this packet Parameters: offset - the offset into the data Parameters: length - the length of the data and/or the length of the buffer used to receive data exception: NullPointerException - if the argument is null See Also: DatagramPacket.getData See Also: DatagramPacket.getOffset See Also: DatagramPacket.getLength since: JDK1.2 |
setData | public synchronized void setData(byte[] buf)(Code) | | 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 .
Parameters: buf - the buffer to set for this packet. exception: NullPointerException - if the argument is null. See Also: DatagramPacket.getLength See Also: DatagramPacket.getData since: JDK1.1 |
setLength | public synchronized void setLength(int length)(Code) | | 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.
Parameters: length - the length to set for this packet. exception: IllegalArgumentException - if the length is negativeof if the length is greater than the packet's data bufferlength. See Also: DatagramPacket.getLength See Also: DatagramPacket.setData since: JDK1.1 |
setPort | public synchronized void setPort(int iport)(Code) | | Sets the port number on the remote host to which this datagram
is being sent.
Parameters: iport - the port number since: JDK1.1 See Also: DatagramPacket.getPort() |
setSocketAddress | public synchronized void setSocketAddress(SocketAddress address)(Code) | | Sets the SocketAddress (usually IP address + port number) of the remote
host to which this datagram is being sent.
Parameters: address - the SocketAddress throws: IllegalArgumentException - if address is null or is aSocketAddress subclass not supported by this socket since: 1.4 See Also: DatagramPacket.getSocketAddress |
|
|