import java.net.*; public class UDPServer { public static void main(String[] a) throws Exception { DatagramSocket s = new DatagramSocket(9876); byte[] buf = new byte[1024]; System.out.println("Server running..."); while (true) { DatagramPacket p = new DatagramPacket(buf, buf.length); s.receive(p); String msg = new String(p.getData(), 0, p.getLength()); byte[] out = ("ACK: " + msg.toUpperCase()).getBytes(); s.send(new DatagramPacket(out, out.length, p.getAddress(), p.getPort())); } } } import java.net.*; import java.io.*; public class UDPClient { public static void main(String[] a) throws Exception { DatagramSocket s = new DatagramSocket(); InetAddress ip = InetAddress.getByName("localhost"); System.out.print("Enter msg: "); byte[] out = new BufferedReader(new InputStreamReader(System.in)).readLine().getBytes(); s.send(new DatagramPacket(out, out.length, ip, 9876)); byte[] buf = new byte[1024]; DatagramPacket p = new DatagramPacket(buf, buf.length); s.receive(p); System.out.println("SERVER: " + new String(p.getData(), 0, p.getLength())); s.close(); } }