-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChristianClient.java
40 lines (32 loc) · 1.06 KB
/
ChristianClient.java
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
39
40
import java.net.*;
import java.io.*;
import java.sql.Timestamp;
import java.util.Date;
class ChristianClient {
public static void main(String args[]) throws Exception {
Socket s = new Socket("localhost", 1102);
DataInputStream din = new DataInputStream(s.getInputStream());
DataOutputStream dout = new DataOutputStream(s.getOutputStream());
long t, t0, t1, st;
Date date;
t0 = System.currentTimeMillis();
t = t0;
date = new Timestamp(t);
System.out.println("Client Time T0: " + date);
dout.writeUTF("Send Time");
dout.flush();
st = Long.parseLong(din.readUTF());
t = st;
date = new Timestamp(t);
System.out.println("Server Time: " + date);
t1 = System.currentTimeMillis();
t = t1;
date = new Timestamp(t);
System.out.println("Client Time T1: " + date);
t = st + (t1-t0)/2;
date = new Timestamp(t);
System.out.println("Client Sync Time: " + date);
dout.close();
s.close();
}
}