Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Network Construct a DatagramPacket to receive data

Related Tutorials


 
 

Share on Google+Share on Google+

Construct a DatagramPacket to receive data

Advertisement
In this section we provide a complete code of a example based on the method

Construct a DatagramPacket to receive data

     

In this section we provide a complete code of a example based on the method DatagramPacket(buffer, buffer.length) for constructs a DatagramPacket for receiving packets of length length in more generic way. First of all create a class UDPReceiver and initialize a object buffer of byte[] array. After that we call the DatagramPacket(buffer, buffer.length) method for creating a datagram packet to receive data.


Here is the code of this example:

 

import java.net.*;

public class UDPReceiver {

  public static void main(String args[]) {
  
  byte[] buffer = new byte[7087];
  DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
  System.out.println("Datagram packet receive.");
  }
}


Here is the Output of the Example :

C:\roseindia>javac UDPReceiver.java

C:\roseindia>java UDPReceiver
Datagram packet receive.


Download of This Example.

 

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 16, 2009

Related Tutorials

Discuss: Construct a DatagramPacket to receive data  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
avnish
April 15, 2011
computer network

what are data gram modeling in the networking?
DMCA.com