-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandshake.html
142 lines (128 loc) · 4.82 KB
/
handshake.html
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TCP Three-Way Handshake Animation</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #222;
color: #eee;
padding-top: 50px;
position: relative;
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
width: 80%;
margin: 50px auto;
position: relative;
}
.box {
width: 160px;
height: 100px;
line-height: 100px;
font-size: 16px;
font-weight: bold;
border-radius: 10px;
border: 2px solid #ccc;
position: relative;
}
.closed { background-color: gray; }
.syn { background-color: #f39c12; }
.established { background-color: #27ae60; }
.packet {
position: absolute;
width: 130px;
height: 45px;
line-height: 45px;
font-size: 14px;
font-weight: bold;
border-radius: 5px;
background-color: #3498db;
color: #fff;
visibility: hidden;
}
.state {
font-size: 14px;
font-weight: bold;
margin-top: 5px;
color: #f1c40f;
}
/* Watermark style */
.watermark {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 50px;
font-weight: bold;
color: rgba(255, 255, 255, 0.15); /* Light color for watermark */
pointer-events: none; /* Ensures it's not interactive */
z-index: 10;
user-select: none; /* Prevents text selection */
}
</style>
</head>
<body>
<!-- Watermark -->
<div class="watermark">wangbin579</div>
<h2>TCP Three-Way Handshake Animation</h2>
<div class="container">
<div>
<div id="clientBox" class="box closed">Client</div>
<div id="clientState" class="state">CLOSED</div>
</div>
<div>
<div id="serverBox" class="box closed">Server</div>
<div id="serverState" class="state">LISTEN</div>
</div>
</div>
<div id="synPacket" class="packet">SYN -></div>
<div id="synAckPacket" class="packet"><- SYN-ACK</div>
<div id="ackPacket" class="packet">ACK -></div>
<script>
function updateState(element, text) {
document.getElementById(element).innerText = text;
}
function startHandshake() {
let clientBox = document.getElementById("clientBox");
let serverBox = document.getElementById("serverBox");
let clientX = clientBox.getBoundingClientRect().x + 80;
let serverX = serverBox.getBoundingClientRect().x + 0;
let syn = document.getElementById("synPacket");
let synAck = document.getElementById("synAckPacket");
let ack = document.getElementById("ackPacket");
// Step 1: Client sends SYN ¡ú Server
updateState("clientState", "SYN_SENT");
clientBox.className = "box syn";
gsap.set(syn, { visibility: "visible", x: clientX, y: -50 });
gsap.to(syn, { x: serverX, duration: 2, onComplete: function() {
gsap.set(syn, { visibility: "hidden" });
// Step 2: Server receives SYN, sends SYN-ACK
updateState("serverState", "SYN_RCVD");
serverBox.className = "box syn";
gsap.set(synAck, { visibility: "visible", x: serverX, y: -50 });
gsap.to(synAck, { x: clientX, duration: 2, onComplete: function() {
gsap.set(synAck, { visibility: "hidden" });
// Step 3: Client receives SYN-ACK, sends ACK
updateState("clientState", "ESTABLISHED");
clientBox.className = "box established";
gsap.set(ack, { visibility: "visible", x: clientX, y: -50 });
gsap.to(ack, { x: serverX, duration: 2, onComplete: function() {
gsap.set(ack, { visibility: "hidden" });
// Step 4: Server receives ACK, connection established
updateState("serverState", "ESTABLISHED");
serverBox.className = "box established";
}});
}});
}});
}
setTimeout(startHandshake, 1000);
</script>
</body>
</html>