1 import java.io.IOException;
2 import java.io.InputStream;
3 import java.net.Socket;
4 import java.util.Scanner;
5
6
7 public class SocketTest {
8 public static void main(String[] args) {
9 Socket s = null;
10 try {
11 s = new Socket("time-A.timefreq.bldrdoc.gov",13);
12 InputStream inStream = s.getInputStream();
13 Scanner in = new Scanner(inStream);
14
15 while(in.hasNextLine()) {
16 String line = in.nextLine();
17 System.out.println(line);
18 }
19
20 } catch (Exception ex) {
21 ex.printStackTrace();
22 }
23 finally {
24 if (s != null) {
25 try {
26 s.close();
27 } catch (IOException e) {
28 // TODO Auto-generated catch block
29 e.printStackTrace();
30 }
31 }
32 }
33 }
34 }
2 import java.io.InputStream;
3 import java.net.Socket;
4 import java.util.Scanner;
5
6
7 public class SocketTest {
8 public static void main(String[] args) {
9 Socket s = null;
10 try {
11 s = new Socket("time-A.timefreq.bldrdoc.gov",13);
12 InputStream inStream = s.getInputStream();
13 Scanner in = new Scanner(inStream);
14
15 while(in.hasNextLine()) {
16 String line = in.nextLine();
17 System.out.println(line);
18 }
19
20 } catch (Exception ex) {
21 ex.printStackTrace();
22 }
23 finally {
24 if (s != null) {
25 try {
26 s.close();
27 } catch (IOException e) {
28 // TODO Auto-generated catch block
29 e.printStackTrace();
30 }
31 }
32 }
33 }
34 }