import java.net.*; /** * Simple UDP receiver (can receive datagrams broadcasted or not) * @author (c)2013 */ public class Receiver { public static void main(String args[]) { try { byte [] data = new byte[256]; DatagramSocket ds = new DatagramSocket(60123); DatagramPacket dp = new DatagramPacket(data,data.length); while (true) { ds.receive(dp); String s = new String(dp.getData(),0,dp.getLength()); System.out.println("Received "+s); } } catch(Exception e) { e.printStackTrace(); } } }