FileDocCategorySizeDatePackage
UDPSend.javaAPI DocExample1326Fri Feb 16 13:29:42 GMT 1996None

UDPSend

public class UDPSend extends Object

Fields Summary
static final int
port
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

           
        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);