import java.util.List; import java.util.LinkedList; import java.util.Iterator; /** *
// Send time requests to all the supplied hosts protected void sendRequests() throws Exception { ByteBuffer buffer = ByteBuffer.allocate (1); Iterator it = remoteHosts.iterator(); while (it.hasNext()) { InetSocketAddress sa = (InetSocketAddress) it.next(); System.out.println (”Requesting time from ” + sa.getHostName() + “:” + sa.getPort()); // Make it empty (see RFC868) buffer.clear().flip(); // Fire and forget channel.send (buffer, sa); } } // Receive any replies that arrive public void getReplies() throws Exception { // Allocate a buffer to hold a long value ByteBuffer longBuffer = ByteBuffer.allocate (8); // Assure big-endian (network) byte order longBuffer.order (ByteOrder.BIG_ENDIAN); // Zero the whole buffer to be sure longBuffer.putLong (0, 0); // Position to first byte of the low-order 32 bits longBuffer.position (4); // Slice the buffer; gives view of the low-order 32 bits ByteBuffer buffer = longBuffer.slice(); int expect = remoteHosts.size(); int replies = 0; System.out.println (”"); System.out.println (”Waiting for replies…”); while (true) { InetSocketAddress sa; sa = receivePacket (channel, buffer); buffer.flip(); replies++; printTime (longBuffer.getLong (0), sa); if (replies == expect) { System.out.println (”All packets answered”); break; } 117
Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider