All About Class DatagramPacket in Java



DatagramPacket class represents a datagram packet.Datagram packets are used to implement a connection less packet delivering service.Each message is routed from one machine to another based solely on the information  contained within the packet.Multiple packets sent from a machine to another might be routed differently and can arrive in any order.

The structure of the class DatagramPacket is given as:

public final class java.net.DatagramPacket extends java.lang.Object{
//Constructors:
public DatagramPacket(bute iBuff[],int iLength);
//constructs a DatagramPacket for a receiving packets of length iLength.The length argument must be
//or equals to iBuff[] length.
public DatagramPacket(bute iBuff[],int iLength,InetAddress iAddress,int portNumber);
//constructs a DatagramPacket for a sending packets of length iLength to the specified port portNumber
//on the specified host iAddress.The length argument must be or equals to iBuff[] length.
//Methods:
public InetAddress getAddress();//returns the destination InetAddress.It is used to send data
public byte[] getData();//returns the byte array of data contained in the datagram. It is used to retrieve
//data from the datagram after it is received.
public int getLength();//returns the length of the valid data contained in the byte array that would
//be returned from getData() method
public int getPort();//returns the integer destination port number.It is used to send data
}
 
All About Class DatagramPacket in Java All About Class DatagramPacket in Java Reviewed by Animesh Chatterjee on October 08, 2018 Rating: 5

No comments:

Powered by Blogger.