List of usage examples for org.apache.commons.net.ntp NTPUDPClient open
public void open(int port, InetAddress laddr) throws SocketException
From source file:org.sipfoundry.preflight.NTP.java
public ResultCode validate(int timeout, NetworkResources networkResources, JournalService journalService, InetAddress bindAddress) { ResultCode results = NONE;/*from w ww . java 2 s . c om*/ if (networkResources.ntpServers == null) { journalService.println("No NTP servers provided, skipping test."); results = NTP_SERVERS_MISSING; } else { journalService.println("Starting NTP servers test."); NTPUDPClient client = new NTPUDPClient(); client.setDefaultTimeout(timeout * 1000); try { client.open(bindPort, bindAddress); for (InetAddress ntpServer : networkResources.ntpServers) { journalService.println("NTP test for server: " + ntpServer.getCanonicalHostName()); try { TimeInfo info = client.getTime(ntpServer); journalService.println(new String(processResponse(info))); } catch (IOException e) { client.close(); if (e.getClass() == java.net.SocketTimeoutException.class) { journalService.println(" NTP request timed out."); results = NTP_SERVER_FAILURE; } else { journalService.println(" NTP request error: " + e.getMessage()); results = NTP_TEST_FAILURE; } } } } catch (SocketException e) { journalService.println("Unable to create NTP client: " + e.getMessage()); results = NTP_TEST_FAILURE; } } journalService.println(""); return results; }