-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtcp_normal_close.html
164 lines (148 loc) · 6.08 KB
/
tcp_normal_close.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>The four-way handshake process of a normal TCP connection closure</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;
}
.established { background-color: #27ae60; }
.fin_wait_1 { background-color: #f39c12; }
.fin_wait_2 { background-color: #e67e22; }
.close_wait { background-color: #d35400; }
.last_ack { background-color: #c0392b; }
.time_wait { background-color: #8e44ad; }
.closed { background-color: gray; }
.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>The four-way handshake process of a normal TCP connection closure</h2>
<div class="container">
<div>
<div id="clientBox" class="box established">Client</div>
<div id="clientState" class="state">ESTABLISHED</div>
</div>
<div>
<div id="serverBox" class="box established">Server</div>
<div id="serverState" class="state">ESTABLISHED</div>
</div>
</div>
<div id="finPacket" class="packet">FIN -></div>
<div id="ackPacket1" class="packet"><- ACK</div>
<div id="finPacket2" class="packet"><- FIN</div>
<div id="ackPacket2" 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 fin = document.getElementById("finPacket");
let ack1 = document.getElementById("ackPacket1");
let fin2 = document.getElementById("finPacket2");
let ack2 = document.getElementById("ackPacket2");
// Step 1: Client sends FIN ¡ú Server
updateState("clientState", "FIN_WAIT_1");
clientBox.className = "box fin_wait_1";
gsap.set(fin, { visibility: "visible", x: clientX, y: -50 });
gsap.to(fin, { x: serverX, duration: 3, onComplete: function() {
gsap.set(fin, { visibility: "hidden" });
// Step 2: Server responds with ACK
updateState("serverState", "CLOSE_WAIT");
serverBox.className = "box close_wait";
gsap.set(ack1, { visibility: "visible", x: serverX, y: -50 });
gsap.to(ack1, { x: clientX, duration: 3, onComplete: function() {
gsap.set(ack1, { visibility: "hidden" });
// Client moves to FIN_WAIT_2
updateState("clientState", "FIN_WAIT_2");
clientBox.className = "box fin_wait_2";
// Step 3: Server sends FIN ¡ú Client
setTimeout(function() {
updateState("serverState", "LAST_ACK");
serverBox.className = "box last_ack";
gsap.set(fin2, { visibility: "visible", x: serverX, y: -50 });
gsap.to(fin2, { x: clientX, duration: 3, onComplete: function() {
gsap.set(fin2, { visibility: "hidden" });
// Step 4: Client responds with ACK
updateState("clientState", "TIME_WAIT");
clientBox.className = "box time_wait";
gsap.set(ack2, { visibility: "visible", x: clientX, y: -50 });
gsap.to(ack2, { x: serverX, duration: 3, onComplete: function() {
gsap.set(ack2, { visibility: "hidden" });
// Final states
updateState("clientState", "CLOSED");
clientBox.className = "box closed";
updateState("serverState", "CLOSED");
serverBox.className = "box closed";
}});
}});
}, 2000); // Delay for Step 3
}});
}});
}
setTimeout(startHandshake, 1000);
</script>
</body>
</html>