All About Class DatagramPacket in Java

0
24
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share


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
}
 
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here