TCP는 논리적인 접속을 성립(establish)하기 위해 3-way handshake를 사용해요.
TCP는 PAR(Positive Acknowledgement with Re-transmission) 이라는 것을 통해 신뢰할 수 있는 통신을 제공해요. 전송 계층의 PDU(Protocol Data Unit)를 세그먼트라고 해요.
아래에서 메커니즘이 어떻게 작동되는지 같이 알아볼까요?

3-way handshake는 초기 연결 설정 프로세스에요. 클라이언트는 먼저 서버에 연결 요청(SYN 패킷)을 보내요. 서버 측에서 메모리 공간 및 기타 리소스를 사용할 수 있는 경우 서버는 들어오는 연결 요청을 수락하고 SYN+ACK 패킷을 전송하여 이를 클라이언트에 ACK합니다. 클라이언트가 이 패킷을 받으면 서버와 실제 통신을 시작하고 다음 패킷부터 GET 요청을 보냅니다. 회신에서 서버는 클라이언트가 요청한 실제 데이터를 보냅니다.
단계별로 알아볼게요.
- 1단계(SYN):
첫 번째 단계에서 클라이언트는 서버와의 연결을 원하기 때문에 SYN(Synchronize Sequence Number)과 함께 세그먼트를 전송하여 클라이언트가 통신을 시작할 가능성이 있음과 세그먼트를 시작하는 번호를 서버에 알려요.
- 2단계(SYN + ACK):
서버는 SYN-ACK 신호 비트 세트로 클라이언트 요청에 응답합니다. ACK(Acknowledgement)는 수신한 세그먼트의 응답을 의미하고 SYN은 세그먼트를 시작할 가능성이 있는 시퀀스 번호를 의미합니다.
- 3단계(ACK):
마지막 부분에서 클라이언트는 서버의 응답을 확인하고 둘 다 실제 데이터 전송을 시작할 안정적인 연결을 설정합니다.’
SYN(Synchronization:동기화) - S : 연결 요청 플래그
TCP 에서 세션을 성립할 때 가장먼저 보내는 패킷, 시퀀스 번호를 임의적으로 설정하여 세션을 연결하는 데에 사용되며 초기에 시퀀스 번호를 보내게 된다.
ACK(Acknowledgement) - Ack : 응답
상대방으로부터 패킷을 받았다는 걸 알려주는 패킷, 다른 플래그와 같이 출력되는 경우도 있습니다.받는 사람이 보낸 사람 시퀀스 번호에 TCP 계층에서 길이 또는 데이터 양을 더한 것과 같은 ACK를 보냅니다.(일반적으로 +1 하여 보냄) ACK 응답을 통해 보낸 패킷에 대한 성공, 실패를 판단하여 재전송 하거나 다음 패킷을 전송한다.
FIN(Finish) - F : 연결 종료 요청
세션 연결을 종료시킬 때 사용되며 더이상 전송할 데이터가 없음을 나타낸다.
3 way handshake 알고리즘
+추가로 더 공부하다 시간이 없었는데 궁금하시면 보세요!


RTT = 56 ms (London to New York) Initial congestion window (initcwnd) = 10 segments 1 segment size = 1460 bytes For the TCP Sender to transmit 64KB simultaneously, it must have a congestion window value of approximately 45 segments. N = (64KB ÷ segment size = 65536 bytes ÷ 1460 bytes = 44.88 segments) Time = RTT x ceil(log2(1 + 45/10)) = RTT x ceil(log2(5.5)) = 56 ms x ceil(2.459) = 56 ms x 3 = 168 ms Thus, the sender would be able to transmit 64 KB simultaneously after 168 ms.
- 모든 TCP 연결은 the slow start phase를 거쳐야 해요.
- 3 way handshake는 초기 연결 설정 프로세스입니당
Step 1: Sender sends the SYN packet at time=0.
Step 2: Receiver gets the SYN packet at time=28 ms, which is one-way time. The receiver accepts the connection request and sends back the SYN+ACK packet at time=28 ms, just after it receives the SYN packet from the sender.
Step 3: The ACK arrives at sender at time=56 ms, another 28 ms was taken by a packet to reach from receiver to sender side, this makes a total of one RTT time, the two-way journey of the packet. Now the connection is established between sender and receiver using 3-way handshakes.
Step 4: Now sender sends the GET request to the receiver at time=56 ms. It takes 28 ms to reach and the receiver gets the GET request.
Step 5: At time=84 ms server receives the GET request.
Step 6: The server takes 40 ms to process the request and generate the data to send in reply packets. After 40 ms elapsed, the server sends the 10 segments of data simultaneously at time=124 ms without waiting for a single ACK to come.
Step 7: The sender or client will start receiving the reply packets one after the other, and it will send the ACK for each packet to the server. The client will get all 10 segments by time=152 ms. On receiving the ACK packets, the server will increase its congestion window size by 1 per ACK packet. Initially, cwnd was 10, therefore it send 10 segments simultaneously. When the server increases its cwnd by 1, it sends 2 new packets into the link.
Step 8: In one RTT time, the server will get the ACK of all 10 packets and thus its cwnd would become 10*2 = 20 at time=180 ms. Also, by this time server has sent 20 new segments into the link, other than the initial 10 segments whose delivery has already been ACK.
Step 9: Now, 20 segments are in the pipe between sender and receiver at time=180 ms.
Step 10: By time=208 ms, the client will receive all these packets.
Step 11: By time=236 server sends 15 new segments. At this time server will get ACK of all these 20 segments. In the intrim, the server will increase its cwnd by 1 per ACK but can’t send 2 new packets for each ACK cause only 15 segments are left to send (total 45 segments). cwnd=40 now.
Step 12: Thus at time=264 ms, 15 segments are reached to the client. Thus 264 ms are required to send 64 KB of data to the client.
Step 13: At time=292 ms, 15 ACK will come to the server, and cwnd will become 40+15 = 55, but the server has no data to send.
So, it takes 264 ms to send 45 packets to the client.
The bandwidth available between server and client is 5 MBPS, but still, the file of 64 KB is taking 264 ms. This time will not decrease even if we increase the bandwidth to 50 MBPS or 5 GBPS. If the client is visiting Gmail or google servers then the page load time will be 264 ms, and this time can’t be decreased by increasing the bandwidth.
264 ms taken by the server to successfully(with ACK) send 45 segments to the client. By formula time taken by Slow Start to grow the cwnd to 64 KB= 168 ms. Server processing time = 40 ms Time elapsed in 3-way Handshakes = 56 ms Total time = 3-way-handshake + server_processing + Slow_start 264 = 56(3-way-handshake) + 40(server response time) + 168(Slow_start) ms Thus, slow start and 3-way Handshakes have wasted = 168 ms + 56 ms = 224 ms.
한번 더 깊게
RTT(Round Trip Time)

왕복 시간/지연이라고도 하는 RTT는 네트워크 상태를 결정하는 데 중요한 도구에요
RTT 계산
계산하고 싶으신가요? 다음과 같은 다이어그램을 통해 표현할 수 있어요.

RTT를 줄이고 싶으신가요?
CDN(Content Delivery Network)을 사용하면 RTT를 크게 줄일 수 있어요.
추가적으로 더 줄이고 싶으신가요?
1. Points of Presence (PoP) 2. Web caching 3. Load distribution 4. Scalability 5. Tier 1 access