FileDocCategorySizeDatePackage
TimeClientSelect.javaAPI DocExample1291Sun Apr 28 12:43:16 BST 2002com.ronsoft.books.nio.channels

TimeClientSelect

public class TimeClientSelect extends TimeClient

Fields Summary
private long
giveup
private Selector
selector
Constructors Summary
public TimeClientSelect(String[] argv, long timeout)

		super (argv);

		this.selector = Selector.open();
		this.channel.configureBlocking (false);
		this.channel.register (selector, SelectionKey.OP_READ);
		this.giveup = System.currentTimeMillis() + timeout;
	
Methods Summary
public static voidmain(java.lang.String[] argv)

		TimeClientSelect client = new TimeClientSelect (argv, 5000);

		client.sendRequests();
		client.getReplies();
	
protected java.net.InetSocketAddressreceivePacket(java.nio.channels.DatagramChannel channel, java.nio.ByteBuffer buffer)

		buffer.clear();

		while (true) {
			InetSocketAddress sa;

			sa = (InetSocketAddress) channel.receive (buffer);

			if (sa != null) {
				return (sa);
			}

			long sleepTime = giveup - System.currentTimeMillis();

			if (sleepTime <= 0) {
				return (null);
			}

System.out.println ("Selecting for " + (sleepTime / 1000) + " seconds");
			selector.select (sleepTime);

		}