FileDocCategorySizeDatePackage
DGKaboom.javaAPI DocExample1422Thu Apr 25 16:26:54 BST 2002com.ronsoft.books.nio.channels

DGKaboom

public class DGKaboom extends Object
Tickle DatagramChannel send() bug. Attempting to send a datagram to a SocketAddress which does not resolve to a real address causes the JVM to crash (tested on linux and solaris 8).
author
Ron Hitchens (ron@ronsoft.com)
version
$Id: DGKaboom.java,v 1.2 2002/04/25 23:26:55 ron Exp $

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] argv)

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