Package java.net |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
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); // Methods public InetAddress getAddress(); public byte[] getData(); public int getLength(); public int getPort(); }
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 a machine to another might be routed differently, and might arrive in any order.
public DatagramPacket(byte ibuf[], int ilength)Constructs a DatagramPacket for receiving packets of length ilength.
The length argument must be less than or equal to ibuf.length
Parameter Description ibuf buffer for holding the incoming datagram ilength the number of bytes to read
public DatagramPacket(byte ibuf[], int ilength, InetAddress iaddr, int iport)Constructs a DatagramPacket for sending packets of length ilength to the specified port number on the specified host.
The length argument must be less than or equal to ibuf.length
Parameter Description ibuf the packet data ilength the packet length iaddr the desination address(§4.4) iport the destination port number
public InetAddress getAddress()Return Value:
Returns the IP address (Class InetAddress) of the machine to which this datagram is being sent, or from which the datagram was received.
public byte[] getData()Return Value:
Returns the data received, or the data to be sent.
public int getLength()Return Value:
Returns the length of the data to be sent, or the length of the data received.
public int getPort()Return Value:
Returns the port number on the remote host to which this datagram is being sent, or from which the dagram was received.