Receiving a Datagram
import java.net.DatagramPacket; import java.net.DatagramSocket; public class Main { public static void main(String[] argv) throws Exception { byte[] inbuf = new byte[256]; // default size DatagramSocket socket = new DatagramSocket(); DatagramPacket packet = new DatagramPacket(inbuf, inbuf.length); socket.receive(packet); int numBytesReceived = packet.getLength(); System.out.println(numBytesReceived); } }