Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
commons-net.jar Source Code
commons-net.jar is the bytecode of Apache Commons Net library, which implements the client side of many basic Internet protocols.
Apache Commons Net Source Code files are provided in the binary packge (commons-net-3.8.0-bin.zip). You can download it at Apache Commons Net Website.
The source code of commons-net-3.8.0.jar is provided below:
✍: FYIcenter
⏎ org/apache/commons/net/ntp/NTPUDPClient.java
package org.apache.commons.net.ntp; /* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.IOException; import java.net.DatagramPacket; import java.net.InetAddress; import org.apache.commons.net.DatagramSocketClient; /** * The NTPUDPClient class is a UDP implementation of a client for the * Network Time Protocol (NTP) described in RFC 1305 as well as the * Simple Network Time Protocol (SNTP) in RFC-2030. To use the class, * merely open a local datagram socket with <a href="#open"> open </a> * and call <a href="#getTime"> getTime </a> to retrieve the time. Then call * <a href="org.apache.commons.net.DatagramSocketClient.html#close"> close </a> * to close the connection properly. * Successive calls to <a href="#getTime"> getTime </a> are permitted * without re-establishing a connection. That is because UDP is a * connectionless protocol and the Network Time Protocol is stateless. * */ public final class NTPUDPClient extends DatagramSocketClient { /** The default NTP port. It is set to 123 according to RFC 1305. */ public static final int DEFAULT_PORT = 123; private int version = NtpV3Packet.VERSION_3; /** * Retrieves the time information from the specified server and port and * returns it. The time is the number of miliiseconds since * 00:00 (midnight) 1 January 1900 UTC, as specified by RFC 1305. * This method reads the raw NTP packet and constructs a <i>TimeInfo</i> * object that allows access to all the fields of the NTP message header. * <p> * @param host The address of the server. * @param port The port of the service. * @return The time value retrieved from the server. * @throws IOException If an error occurs while retrieving the time. */ public TimeInfo getTime(final InetAddress host, final int port) throws IOException { // if not connected then open to next available UDP port if (!isOpen()) { open(); } final NtpV3Packet message = new NtpV3Impl(); message.setMode(NtpV3Packet.MODE_CLIENT); message.setVersion(version); final DatagramPacket sendPacket = message.getDatagramPacket(); sendPacket.setAddress(host); sendPacket.setPort(port); final NtpV3Packet recMessage = new NtpV3Impl(); final DatagramPacket receivePacket = recMessage.getDatagramPacket(); /* * Must minimize the time between getting the current time, * timestamping the packet, and sending it out which * introduces an error in the delay time. * No extraneous logging and initializations here !!! */ final TimeStamp now = TimeStamp.getCurrentTime(); // Note that if you do not set the transmit time field then originating time // in server response is all 0's which is "Thu Feb 07 01:28:16 EST 2036". message.setTransmitTime(now); _socket_.send(sendPacket); _socket_.receive(receivePacket); final long returnTimeMillis = System.currentTimeMillis(); // create TimeInfo message container but don't pre-compute the details yet return new TimeInfo(recMessage, returnTimeMillis, false); } /** * Retrieves the time information from the specified server on the * default NTP port and returns it. The time is the number of miliiseconds * since 00:00 (midnight) 1 January 1900 UTC, as specified by RFC 1305. * This method reads the raw NTP packet and constructs a <i>TimeInfo</i> * object that allows access to all the fields of the NTP message header. * <p> * @param host The address of the server. * @return The time value retrieved from the server. * @throws IOException If an error occurs while retrieving the time. */ public TimeInfo getTime(final InetAddress host) throws IOException { return getTime(host, NtpV3Packet.NTP_PORT); } /** * Returns the NTP protocol version number that client sets on request packet * that is sent to remote host (e.g. 3=NTP v3, 4=NTP v4, etc.) * * @return the NTP protocol version number that client sets on request packet. * @see #setVersion(int) */ public int getVersion() { return version; } /** * Sets the NTP protocol version number that client sets on request packet * communicate with remote host. * * @param version the NTP protocol version number */ public void setVersion(final int version) { this.version = version; } }
⏎ org/apache/commons/net/ntp/NTPUDPClient.java
Or download all of them as a single archive file:
File name: commons-net-3.8.0-sources.jar File size: 437325 bytes Release date: 2020-01-22 Download
⇒ Download and Install commons-net.jar Binary Package
2009-02-08, 144947👍, 0💬
Popular Posts:
io.jar is a component in iText Java library to provide input/output functionalities. iText Java libr...
Where to find answers to frequently asked questions on Downloading and Using JDK (Java Development K...
Provides a simple high-level Http server API, which can be used to build embedded HTTP servers. Both...
JDK 11 jdk.internal.le.jmod is the JMOD file for JDK 11 Internal Line Editing module. JDK 11 Interna...
JDK 11 jdk.aot.jmod is the JMOD file for JDK 11 Ahead-of-Time (AOT) Compiler module. JDK 11 AOT Comp...