|
TV-Browser 3.3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object util.io.NtpMessage
public class NtpMessage
This class represents a NTP message, as specified in RFC 2030. The message format is compatible with all versions of NTP and SNTP. This class does not support the optional authentication protocol, and ignores the key ID and message digest fields. For convenience, this class exposes message values as native Java types, not the NTP-specified data formats. For example, timestamps are stored as doubles (as opposed to the NTP unsigned 64-bit fixed point format). However, the contructor NtpMessage(byte[]) and the method toByteArray() allow the import and export of the raw NTP message format. Usage example // Send message DatagramSocket socket = new DatagramSocket(); InetAddress address = InetAddress.getByName("ntp.cais.rnp.br"); byte[] buf = new NtpMessage().toByteArray(); DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 123); socket.send(packet); // Get response socket.receive(packet); System.out.println(msg.toString()); This code is copyright (c) Adam Buckley 2004 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. A HTML version of the GNU General Public License can be seen at http://www.gnu.org/licenses/gpl.html This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Comments for member variables are taken from RFC2030 by David Mills, University of Delaware. Number format conversion code in NtpMessage(byte[] array) and toByteArray() inspired by http://www.pps.jussieu.fr/~jch/enseignement/reseaux/ NTPMessage.java which is copyright (c) 2003 by Juliusz Chroboczek
Field Summary | |
---|---|
byte |
leapIndicator
This is a two-bit code warning of an impending leap second to be inserted/deleted in the last minute of the current day. |
byte |
mode
This value indicates the mode, with values defined as follows: Mode Meaning ---- ------- 0 reserved 1 symmetric active 2 symmetric passive 3 client 4 server 5 broadcast 6 reserved for NTP control message 7 reserved for private use In unicast and anycast modes, the client sets this field to 3 (client) in the request and the server sets it to 4 (server) in the reply. |
double |
originateTimestamp
This is the time at which the request departed the client for the server, in seconds since 00:00 1-Jan-1900. |
byte |
pollInterval
This value indicates the maximum interval between successive messages, in seconds to the nearest power of two. |
byte |
precision
This value indicates the precision of the local clock, in seconds to the nearest power of two. |
double |
receiveTimestamp
This is the time at which the request arrived at the server, in seconds since 00:00 1-Jan-1900. |
byte[] |
referenceIdentifier
This is a 4-byte array identifying the particular reference source. |
double |
referenceTimestamp
This is the time at which the local clock was last set or corrected, in seconds since 00:00 1-Jan-1900. |
double |
rootDelay
This value indicates the total roundtrip delay to the primary reference source, in seconds. |
double |
rootDispersion
This value indicates the nominal error relative to the primary reference source, in seconds. |
short |
stratum
This value indicates the stratum level of the local clock, with values defined as follows: Stratum Meaning ---------------------------------------------- 0 unspecified or unavailable 1 primary reference (e.g., radio clock) 2-15 secondary reference (via NTP or SNTP) 16-255 reserved |
double |
transmitTimestamp
This is the time at which the reply departed the server for the client, in seconds since 00:00 1-Jan-1900. |
byte |
version
This value indicates the NTP/SNTP version number. |
Constructor Summary | |
---|---|
NtpMessage()
Constructs a new NtpMessage in client -> server mode, and sets the transmit timestamp to the current time. |
|
NtpMessage(byte[] array)
Constructs a new NtpMessage from an array of bytes. |
Method Summary | |
---|---|
static double |
decodeTimestamp(byte[] array,
int pointer)
Will read 8 bytes of a message beginning at pointer
and return it as a double, according to the NTP 64-bit timestamp
format. |
static void |
encodeTimestamp(byte[] array,
int pointer,
double timestamp)
Encodes a timestamp in the specified position in the message |
static java.lang.String |
referenceIdentifierToString(byte[] ref,
short stratum,
byte version)
Returns a string representation of a reference identifier according to the rules set out in RFC 2030. |
static java.lang.String |
timestampToString(double timestamp)
Returns a timestamp (number of seconds since 00:00 1-Jan-1900) as a formatted date/time string. |
byte[] |
toByteArray()
This method constructs the data bytes of a raw NTP packet. |
java.lang.String |
toString()
Returns a string representation of a NtpMessage |
static short |
unsignedByteToShort(byte b)
Converts an unsigned byte to a short. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public byte leapIndicator
public byte version
public byte mode
public short stratum
public byte pollInterval
public byte precision
public double rootDelay
public double rootDispersion
public byte[] referenceIdentifier
public double referenceTimestamp
public double originateTimestamp
public double receiveTimestamp
public double transmitTimestamp
Constructor Detail |
---|
public NtpMessage(byte[] array)
public NtpMessage()
Method Detail |
---|
public byte[] toByteArray()
public java.lang.String toString()
toString
in class java.lang.Object
public static short unsignedByteToShort(byte b)
public static double decodeTimestamp(byte[] array, int pointer)
pointer
and return it as a double, according to the NTP 64-bit timestamp
format.
public static void encodeTimestamp(byte[] array, int pointer, double timestamp)
public static java.lang.String timestampToString(double timestamp)
public static java.lang.String referenceIdentifierToString(byte[] ref, short stratum, byte version)
|
TV-Browser 3.3.3 API | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |