TCP three-way handshake

TCP 3방향 핸드셰이크

Client and server establish a connection by exchanging SYN, SYN-ACK, and ACK.

···
html
<div class="demo"><div class="head"><b>TCP CONNECT</b><span id="state">SYN</span></div><div class="scene"><div class="endpoint">CLIENT</div><div class="packets"><div class="packet" id="syn">SYN <span>→</span></div><div class="packet" id="synack"><span>←</span> SYN-ACK</div><div class="packet" id="ack">ACK <span>→</span></div></div><div class="endpoint">SERVER</div></div><div class="foot"><span id="caption">1 / 3 · request connection</span><span>tap to step</span></div></div>
css
.demo{width:min(94vw,690px);height:min(86vh,310px);padding:clamp(10px,2.4vmin,20px);border:1px solid var(--line);border-radius:14px;background:var(--surface);display:flex;flex-direction:column;gap:clamp(7px,2vmin,14px);font:600 clamp(9px,2.5vmin,15px)/1.3 ui-monospace,monospace}.head,.foot{display:flex;justify-content:space-between;gap:8px}.head b,#state{color:var(--accent)}.foot{color:var(--muted);font-size:.82em}.scene{flex:1;min-height:0;display:flex;align-items:center;gap:clamp(5px,1.7vmin,15px)}.endpoint{border:1px solid var(--line);border-radius:8px;padding:.6em .5em;background:var(--bg);min-width:17%;text-align:center}.packets{flex:1;display:grid;gap:clamp(4px,1.2vmin,9px)}.packet{border:1px solid var(--line);border-radius:6px;color:var(--muted);padding:.28em .6em;opacity:.38;transition:opacity .3s,background .3s,transform .3s}.packet span{color:var(--accent)}.packet:nth-child(2){text-align:right}.packet.on{opacity:1;background:color-mix(in srgb,var(--accent) 14%,var(--surface));border-color:var(--accent);color:var(--fg);transform:scale(1.02)}
js
const ids=['syn','synack','ack'],captions=['request connection','accept and acknowledge','acknowledge server'];let step=0;function draw(){ids.forEach((id,i)=>document.getElementById(id).classList.toggle('on',i===step));document.getElementById('state').textContent=ids[step].toUpperCase().replace('SYNACK','SYN-ACK');document.getElementById('caption').textContent=(step+1)+' / 3 · '+captions[step];step=(step+1)%3}draw();const timer=setInterval(draw,700);document.querySelector('.demo').addEventListener('pointerdown',()=>{clearInterval(timer);draw()})

To open a TCP connection, the client sends SYN, the server replies with SYN-ACK, and the client returns ACK. Both sides have now acknowledged the other side’s initial sequence number.

The three arrows in the demo follow the packet order. This exchange starts a reliable connection; retransmission and ordered delivery continue during the later data transfer.

When to use

Use it when diagnosing connection latency or reading the opening packets of a TCP capture.

Open as page ↗