import java.util.List; import java.util.LinkedList; import java.util.Iterator; /** *
import java.util.List; import java.util.LinkedList; import java.util.Iterator; /** * Request time service, per RFC 868. RFC 868 * (http://www.ietf.org/rfc/rfc0868.txt) is a very simple time protocol * whereby one system can request the current time from another system. * Most Linux, BSD and Solaris systems provide RFC 868 time service * on port 37. This simple program will inter-operate with those. * The National Institute of Standards and Technology (NIST) operates * a public time server at time.nist.gov. * * The RFC 868 protocol specifies a 32 bit unsigned value be sent, * representing the number of seconds since Jan 1, 1900. The Java * epoch begins on Jan 1, 1970 (same as unix) so an adjustment is * made by adding or subtracting 2,208,988,800 as appropriate. To * avoid shifting and masking, a four-byte slice of an * eight-byte buffer is used to send/recieve. But getLong() * is done on the full eight bytes to get a long value. * * When run, this program will issue time requests to each hostname * given on the command line, then enter a loop to receive packets. * Note that some requests or replies may be lost, which means * this code could block forever. * * @author Ron Hitchens (ron@ronsoft.com) */ public class TimeClient{ private static final int DEFAULT_TIME_PORT = 37; private static final long DIFF_1900 = 2208988800L; protected int port = DEFAULT_TIME_PORT; protected List remoteHosts; protected DatagramChannel channel; public TimeClient (String [] argv) throws Exception { if (argv.length == 0) { throw new Exception (”Usage: [ -p port ] host …”); } parseArgs (argv); this.channel = DatagramChannel.open(); } protected InetSocketAddress receivePacket (DatagramChannel channel, ByteBuffer buffer) throws Exception { buffer.clear(); // Receive an unsigned 32-bit, big-endian value return ((InetSocketAddress) channel.receive (buffer)); } 116
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