if (args.length != 2) {
System.out.println("Usage: java UDPSend <hostname> <message>");
System.exit(0);
}
// Get the internet address of the specified host
InetAddress address = InetAddress.getByName(args[0]);
// Convert the message to an array of bytes
int msglen = args[1].length();
byte[] message = new byte[msglen];
args[1].getBytes(0, msglen, message, 0);
// Initilize the packet with data and address
DatagramPacket packet = new DatagramPacket(message, msglen,
address, port);
// Create a socket, and send the packet through it.
DatagramSocket socket = new DatagramSocket();
socket.send(packet);