java.net.DatagramPacket
java.lang.Object
None
None
JDK 1.0 or later
The DatagramPacket class represents a packet of data that can be sent and received over the network using a DatagramSocket. The class is used to implement connectionless data communication.
public final class java.net.DatagramPacket extends java.lang.Object { // Constructors public DatagramPacket(byte[] ibuf, int ilength); public DatagramPacket(byte[] ibuf, int ilength, InetAddress iaddr, int iport); // Instance Methods public synchronized InetAddress getAddress(); public synchronized byte[] getData(); public synchronized int getLength(); public synchronized int getPort(); public synchronized void setAddress(InetAddress iaddr); // New in 1.1 public synchronized void setData(byte[] ibuf); // New in 1.1 public synchronized void setLength(int ilength); // New in 1.1 public synchronized void setPort(int iport); // New in 1.1 }
The data buffer for receiving incoming bytes.
The number of bytes to read.
This constructor creates a DatagramPacket that receives data. The value of ilength must be less than or equal to ibuf.length. This DatagramPacket can be passed to DatagramSocket.receive().
public DatagramPacket(byte ibuf[], int ilength, InetAddress iaddr, int iport)
The data buffer for the packet.
The number of bytes to send.
The destination address.
The destination port number.
This constructor creates a DatagramPacket that sends packets of length ilength to the given port of the specified address. The value of ilength must be less than or equal to ibuf.length. The packets are sent using DatagramSocket.send().
The IP address of the packet.
If this packet has been received, the method returns the address of the machine that sent it. If the packet is being sent, the method returns the destination address.
The packet data.
This method returns the data buffer associated with this DatagramPacket object. This data is either the data being sent or the data that has been received.
The packet length.
This method returns the length of the message in the buffer associated with this DatagramPacket. This length is either the length of the data being sent or the length of the data that has been received.
The port number of the packet.
If this packet has been received, the method returns the port number of the machine that sent it. If the packet is being sent, the method returns the destination port number.
New as of JDK 1.1
The destination address for the packet.
This method sets the destination address for this packet. When the packet is sent using DatagramSocket.send(), it is sent to the specified address.
New as of JDK 1.1
The data buffer for the packet.
This method sets the data for this packet. When the packet is sent using DatagramSocket.send(), the specified data is sent.
New as of JDK 1.1
The number of bytes to send.
This method sets the length of the data to be sent for this packet. When the packet is sent using DatagramSocket.send(), the specified amount of data is sent.
New as of JDK 1.1
The port number for the packet.
This method sets the destination port number for this packet. When the packet is sent using DatagramSocket.send(), it is sent to the specified port.
Method |
Inherited From |
Method |
Inherited From |
---|---|---|---|
clone() |
Object |
equals(Object) |
Object |
finalize() |
Object |
getClass() |
Object |
hashCode() |
Object |
notify() |
Object |
notifyAll() |
Object |
toString() |
Object |
wait() |
Object |
wait(long) |
Object |
wait(long, int) |
Object |
DatagramSocket, InetAddress
This HTML Help has been published using the chm2web software. |