import java.net.DatagramPacket; import java.net.DatagramSocket; public class UDPServer { public static void main(String args[]) { // receive data sent to port 1027 int port = 1027; // receives a byte array of size 1 (for demonstration) int size = 1; byte[] data = new byte[size]; DatagramPacket packet = new DatagramPacket(data, size); try { DatagramSocket udp_service = new DatagramSocket(port); while (true) { System.out.println("Waiting for a packet ..."); udp_service.receive(packet); System.out.println("Received: " + data[0]); } } catch(Exception e) { e.printStackTrace(); } } }