{"id":475,"date":"2013-07-07T13:42:01","date_gmt":"2013-07-07T05:42:01","guid":{"rendered":"http:\/\/blog.staryland.com\/?p=475"},"modified":"2013-07-07T13:42:01","modified_gmt":"2013-07-07T05:42:01","slug":"%e5%88%a9%e7%94%a8java%e8%8e%b7%e5%8f%96%e7%bd%91%e7%bb%9c%e6%a0%87%e5%87%86%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/zhuangzr.me\/wordpress\/2013\/07\/%e5%88%a9%e7%94%a8java%e8%8e%b7%e5%8f%96%e7%bd%91%e7%bb%9c%e6%a0%87%e5%87%86%e6%97%b6%e9%97%b4\/","title":{"rendered":"\u5229\u7528Java\u83b7\u53d6\u7f51\u7edc\u6807\u51c6\u65f6\u95f4"},"content":{"rendered":"<pre class=\"brush: java; title: ; notranslate\" title=\"\">import java.net.*;\nimport java.io.*;\npublic class DaytimeClient\n{\n\t\/**\n\t * @param args\n\t *\/\n\tpublic static void main(String&#x5B;] args)\n\t{\n\t\t\/\/ TODO Auto-generated method stub\n\t\tString&#x5B;] hostname = new String&#x5B;]{&quot;&quot;, &quot;time.windows.com&quot;,&quot;time.nist.gov&quot;,&quot;time-nw.nist.gov&quot;,&quot;time-a.nist.gov&quot;,&quot;time-b.nist.gov&quot;};\n\t\tint i = 1;\n\t\tboolean RecvFlag = false;\n\t\tif(args.length &amp;gt; 0)\n\t\t{\n\t\t\thostname&#x5B;0] = args&#x5B;0];\n\t\t\ti = 0;\n\t\t}\n\t\twhile(i &amp;lt;=5 &amp;amp;&amp;amp; !RecvFlag)\n\t\t{\n\t\t\ttry\n\t\t\t{\n\t\t\t\tSocket timeSocket = new Socket(hostname&#x5B;i], 13);\n\t\t\t\tInputStream timeStream = timeSocket.getInputStream();\n\t\t\t\tStringBuffer time = new StringBuffer();\n\t\t\t\tint c;\n\t\t\t\twhile((c=timeStream.read()) != -1)\n\t\t\t\t\ttime.append((char)c);\n\t\t\t\tString timeString = time.toString().trim();\n\t\t\t\tSystem.out.println(&quot;It is &quot; + timeString +&quot; at &quot; + hostname&#x5B;i] +&quot; on port &quot; + timeSocket.getPort());\n\t\t\t\tRecvFlag = true;\n\t\t\t\ttimeSocket.close();\n\t\t\t}\n\t\t\tcatch(UnknownHostException e)\n\t\t\t{\n\t\t\t\tSystem.out.println(&quot;Failed to get the information from &quot; + hostname&#x5B;i]);\n\t\t\t\tSystem.out.println(e);\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tcatch(Exception e)\n\t\t\t{\n\t\t\t\tSystem.out.println(&quot;Failed to get the information from &quot; + hostname&#x5B;i]);\n\t\t\t\tSystem.out.println(e);\n\t\t\t\ti++;\n\t\t\t}\n\t\t}\n\t\tif(i == 6)\n\t\t\tSystem.out.println(&quot;Failed to get the information please check your network settings.&quot;);\n\t\telse\n\t\t\tSystem.out.println(&quot;Complete.&quot;);\n\t}\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>import java.net.*; import java.io.*; public class DaytimeClient { \/** * @param args *\/ public static void main(String&#x5B;] args) { \/\/ TODO Auto-generated method stub String&#x5B;] hostname = new String&#x5B;]{&quot;&quot;, &quot;time.windows.com&quot;,&quot;time.nist.gov&quot;,&quot;time-nw.nist.gov&quot;,&quot;time-a.nist.gov&quot;,&quot;time-b.nist.gov&quot;}; int i = 1; boolean RecvFlag = false; if(args.length &amp;gt; 0) { hostname&#x5B;0] = args&#x5B;0]; i = 0; } while(i &amp;lt;=5 &amp;amp;&amp;amp; !RecvFlag) { try &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/zhuangzr.me\/wordpress\/2013\/07\/%e5%88%a9%e7%94%a8java%e8%8e%b7%e5%8f%96%e7%bd%91%e7%bb%9c%e6%a0%87%e5%87%86%e6%97%b6%e9%97%b4\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;\u5229\u7528Java\u83b7\u53d6\u7f51\u7edc\u6807\u51c6\u65f6\u95f4&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"class_list":["post-475","post","type-post","status-publish","format-standard","hentry","category-java"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/comments?post=475"}],"version-history":[{"count":0,"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/posts\/475\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/media?parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/categories?post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuangzr.me\/wordpress\/wp-json\/wp\/v2\/tags?post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}