Files
corejava/corejava第10版/v2ch04/socket/SocketTest.java
T
2019-05-22 19:31:49 +08:00

29 lines
642 B
Java

package socket;
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.
*
* @version 1.21 2016-04-27
* @author Cay Horstmann
*/
public class SocketTest
{
public static void main(String[] args) throws IOException
{
try (Socket s = new Socket("time-a.nist.gov", 13);
Scanner in = new Scanner(s.getInputStream(), "UTF-8"))
{
while (in.hasNextLine())
{
String line = in.nextLine();
System.out.println(line);
}
}
}
}