当前位置: 首页>>代码示例>>Java>>正文


Java NTPUDPClient.close方法代码示例

本文整理汇总了Java中org.apache.commons.net.ntp.NTPUDPClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java NTPUDPClient.close方法的具体用法?Java NTPUDPClient.close怎么用?Java NTPUDPClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.net.ntp.NTPUDPClient的用法示例。


在下文中一共展示了NTPUDPClient.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurrentTime

import org.apache.commons.net.ntp.NTPUDPClient; //导入方法依赖的package包/类
private long getCurrentTime() {
    long currentTime = 0;
    NTPUDPClient client = new NTPUDPClient();
    client.setDefaultTimeout(WAIT_FOR_SERVER_RESPONSE);
    try {
        client.open();
        SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, MMM dd yyyy HH:mm:ss.SSS zzz");
        for (String server : NTP_SERVERS) {
            try {
                InetAddress ioe = InetAddress.getByName(server);
                TimeInfo info = client.getTime(ioe);
                TimeStamp ntpTime = TimeStamp.getNtpTime(info.getReturnTime());
                return ntpTime.getTime();
            } catch (Exception e2) {
                System.out.println("Can't get response from server: " + server + ".");
            }
        }
    } catch (SocketException se) {
        System.out.println("Can't open client session");
    } finally {
        client.close();
    }
    return currentTime;
}
 
开发者ID:axibase,项目名称:atsd-web-test,代码行数:25,代码来源:AdminServiceTest.java

示例2: getNTPDate

import org.apache.commons.net.ntp.NTPUDPClient; //导入方法依赖的package包/类
public static String getNTPDate() {

		String[] hosts = new String[] { "ntp02.oal.ul.pt", "ntp04.oal.ul.pt",
				"ntp.xs4all.nl", "time.foo.com", "time.nist.gov" };

		NTPUDPClient client = new NTPUDPClient();
		// We want to timeout if a response takes longer than 5 seconds
		client.setDefaultTimeout(2000);
		SimpleDateFormat OutPutFormat = new SimpleDateFormat(
				"dd/M/yyyy HH:mm:ss", java.util.Locale.getDefault());
		for (String host : hosts) {
			try {
				InetAddress hostAddr = InetAddress.getByName(host);
				TimeInfo info = client.getTime(hostAddr);
				Date date = new Date(info.getReturnTime());
				String out = OutPutFormat.format(date);
				return out;
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		client.close();
		return null;
	}
 
开发者ID:AmulaySoftGroup,项目名称:TaBeTa,代码行数:25,代码来源:GameActivity.java

示例3: updateOffSet

import org.apache.commons.net.ntp.NTPUDPClient; //导入方法依赖的package包/类
private static void updateOffSet()
{
	//CREATE CLIENT
	NTPUDPClient client = new NTPUDPClient();
   
	//SET TIMEOUT
	client.setDefaultTimeout(10000);
	try 
	{
		//OPEN CLIENT
		client.open();
         
		//GET INFO FROM NTP SERVER
		InetAddress hostAddr = InetAddress.getByName(NTP_SERVER);
		TimeInfo info = client.getTime(hostAddr);
		info.computeDetails();
          
		//UPDATE OFFSET
		if(info.getOffset() != null)
		{
			offset = info.getOffset();
		} 
	} 
	catch (Exception e) 
	{
   	   	//ERROR GETTING OFFSET
	}

	client.close(); 
  }
 
开发者ID:razakal,项目名称:Qora,代码行数:31,代码来源:NTP.java

示例4: main

import org.apache.commons.net.ntp.NTPUDPClient; //导入方法依赖的package包/类
public static void main(String[] args) {
	if (args.length == 0) {
		System.err.println("Usage: NTPClient <hostname-or-address-list>");
		System.exit(1);
	}

	NTPUDPClient client = new NTPUDPClient();
	// We want to timeout if a response takes longer than 10 seconds
	client.setDefaultTimeout(10000);
	try {
		client.open();
		for (String arg : args) {
			System.out.println();
			try {
				InetAddress hostAddr = InetAddress.getByName(arg);
				System.out.println("> " + hostAddr.getHostName() + "/"
						+ hostAddr.getHostAddress());
				TimeInfo info = client.getTime(hostAddr);
				processResponse(info);
			} catch (IOException ioe) {
				ioe.printStackTrace();
			}
		}
	} catch (SocketException e) {
		e.printStackTrace();
	}

	client.close();
}
 
开发者ID:rafalmag,项目名称:EV3-projects,代码行数:30,代码来源:NTPClient.java


注:本文中的org.apache.commons.net.ntp.NTPUDPClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。