String host = "foo.bar";
int port = 37;
if (argv.length > 0) {
host = argv [0];
}
if (argv.length > 1) {
port = Integer.parseInt (argv [1]);
}
DatagramChannel dc = DatagramChannel.open();
ByteBuffer bb = ByteBuffer.allocate (4);
InetSocketAddress sa = new InetSocketAddress (host, port);
InetAddress inetaddr = sa.getAddress();
if (inetaddr == null) {
System.out.println ("No address resolved for " + host);
} else {
System.out.println ("Address of " + host
+ " is " + inetaddr);
}
System.out.println ("Attempting send to " + sa);
// if sa does not resolve to an address, kablooey
dc.send (bb, sa);
System.out.println ("Sent OK");
dc.close();