-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaytimeclient.java
More file actions
38 lines (28 loc) · 819 Bytes
/
Copy pathdaytimeclient.java
File metadata and controls
38 lines (28 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//A Program for Daytime protocol client//
import java.net.*;
import java.io.*;
public class daytimeclient {
public static void main(String[] args) {
Socket theSocket;
String hostname;
DataInputStream theTimeStream;
if (args.length > 0) {
hostname = args[0];
}
else {
hostname = "localhost";
}
try {
theSocket = new Socket(hostname, 1397);
theTimeStream = new DataInputStream(theSocket.getInputStream());
String theTime = theTimeStream.readLine();
System.out.println("It is " + theTime + " at " + hostname);
} // end try
catch (UnknownHostException e) {
System.err.println(e);
}
catch (IOException e) {
System.err.println(e);
}
} // end main
} // end daytimeClient