Topic: java如何獲取NTP服務時間? |
Print this page |
1.java如何獲取NTP服務時間? | Copy to clipboard |
Posted by: skwujinhua Posted on: 2008-10-14 09:19 各位老鳥﹐工作上有點問題﹐請教。 用java編程﹐通過NTP服務器的IP地址得到NTP服務器的時間﹐我該怎么做? 脆求﹗﹗﹗可不可以給我源代碼? 問題解決請吃飯。(深圳地區) |
2.Re:java如何獲取NTP服務時間? [Re: skwujinhua] | Copy to clipboard |
Posted by: JiafanZhou Posted on: 2008-10-14 17:24 I'm not familiar with the NTP server to be honest, but I do believe in that there is no difference between a NTP server and other standard servers. Let me introduce the following wikipedia page for NTP protocol. http://en.wikipedia.org/wiki/Network_Time_Protocol The page stated as "NTP uses UDP port 123 as its transport layer. It is designed particularly to resist the effects of variable latency by using a jitter buffer.". Therefore first of all, it is better to check the NTP server that you are working on has the transport port [UDP] 123 opened or not. Maybe do a telnet will identify this very quickly. If the targeted port 123 is not opened on the server (which I think is very impossible), then you need to find the manual or any document to find out which port running NTP protocol is opened on your server. Secondly, the page also stated that "The operational details of NTP are illustrated in RFC 778, RFC 891, RFC 956, RFC 958, and RFC 1305. The current reference implementation is version 4 (NTPv4); however, as of 2005, only versions up to 3 (1992) have been documented in RFCs. The IETF NTP Working Group has formed to standardize the work of the NTP community since RFC 1305 et al." Therefore you need to find out which version of NTP your server is operating on. This could be done by looking at the above RFC documents first. For example, do a very quick tcpdump or pdu (protocol data unit) capture will identify this. Once you have all these questions cleared out, you can implement network code in Java very easily. Nearly every network book mentions this part. Let me introduce this book for you: http://books.google.ie/books?hl=en&id=NyxObrhTv5oC&dq=java+network+programming&printsec=frontcover&source=web&ots=1dbMAIYlNW&sig=FLdQwEeaK0METOjeuM78AJGhq1A&sa=X&oi=book_result&resnum=5&ct=result Also see the below example as a UDP network application for a start:
You would use this constructor in a client that initiates a conversation with a server. In this scenario, you don't care what port the socket is bound to, because the server will send its response to the port from which the datagram originated. Letting the system assign a port means that you don't have to worry about finding an unused port. If for some reason you need to know the local port, you can find out with the getLocalPort( ) method described later in this chapter. The same socket can receive the datagrams that a server sends back to it. A SocketException is thrown if the socket can't be created. It's unusual for this constructor to throw an exception; it's hard to imagine situations in which the socket could not be opened, since the system gets to choose the local port. Jiafan |
3.Re:java如何獲取NTP服務時間? [Re: skwujinhua] | Copy to clipboard |
Posted by: skwujinhua Posted on: 2008-10-15 08:20 謝謝版主﹐研究中.有問題再請教。(對了﹐你的英語真行。) |
4.Re:java如何獲取NTP服務時間? [Re: skwujinhua] | Copy to clipboard |
Posted by: skwujinhua Posted on: 2008-10-15 11:50 大哥﹐你知道不知道怎么分析數據包? 對數據包進行處理? |
5.Re:java如何獲取NTP服務時間? [Re: skwujinhua] | Copy to clipboard |
Posted by: JiafanZhou Posted on: 2008-10-15 18:07 Link this thread to the following one: http://www.cjsdn.net/post/view?bid=1&id=196300&tpg=1&ppg=1&sty=1 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |