Receive DatagramPacket
import java.net.DatagramPacket; import java.net.DatagramSocket; class Collector { private final static int BUFSIZE = 20; public static void main(String args[]) throws Exception { int port = Integer.parseInt(args[0]); DatagramSocket ds = new DatagramSocket(port); while (true) { byte buffer[] = new byte[BUFSIZE]; DatagramPacket dp = new DatagramPacket(buffer, buffer.length); ds.receive(dp); System.out.println(new String(dp.getData())); } } }