sockettest.java

来自「这是java2核心技术第七版的源代码」· Java 代码 · 共 44 行

JAVA
44
字号
/**
   @version 1.20 2004-08-03
   @author Cay Horstmann
*/

import java.io.*;
import java.net.*;
import java.util.*;

/**
   This program makes a socket connection to the atomic clock
   in Boulder, Colorado, and prints the time that the 
   server sends.
*/
public class SocketTest
{  
   public static void main(String[] args)
   {  
      try
      {  
         Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
         try
         {
            InputStream inStream = s.getInputStream();
            Scanner in = new Scanner(inStream);
            
            while (in.hasNextLine())
            {  
               String line = in.nextLine();
               System.out.println(line);
            }
         }
         finally
         {
            s.close();
         }
      }
      catch (IOException e)
      {  
         e.printStackTrace();
      }
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?