CS/Network

[๋„คํŠธ์›Œํฌ] TCP ์—ฐ๊ฒฐ/ํ•ด์ œ ๊ณผ์ •(3 way handshake & 4 way handshake)

๊ฐœ๋ฐœ๊ฐœ๊ตด๐Ÿธ 2023. 10. 29. 15:56

TCP๊ฐ€ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ• ๋•Œ, ์‹ ๋ขฐ์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•œ ์—ฐ๊ฒฐ ์„ฑ๋ฆฝ๊ณผ ์—ฐ๊ฒฐ ํ•ด์ œ ๊ณผ์ •์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

https://j-su2.tistory.com/15

 

[๋„คํŠธ์›Œํฌ] TCP์™€ UDP

TCP์™€ UDP๋Š” ์ „์†ก ๊ณ„์ธต์—์„œ ํ†ต์‹  ํ™œ์„ฑํ™”๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉ๋˜๋Š” ํ”„๋กœํ† ์ฝœ์ž…๋‹ˆ๋‹ค. TCP : ์‹ ๋ขฐ์„ฑ, ์—ฐ๊ฒฐ ์ง€ํ–ฅ์  UDP : ๋น„์‹ ๋ขฐ์„ฑ, ๋น„์—ฐ๊ฒฐ์„ฑ, ์‹ค์‹œ๊ฐ„ ํ”„๋กœํ† ์ฝœ์ด๋ž€? ํ†ต์‹  ๊ทœ์•ฝ์œผ๋กœ ์ปดํ“จํ„ฐ ๋‚ด๋ถ€์—์„œ, ๋˜๋Š” ์ปดํ“จํ„ฐ

j-su2.tistory.com


3 way handshake

TCP๋Š” ์—ฐ๊ฒฐ์„ ์œ„ํ•ด์„œ 3๋ฒˆ์˜ ๊ณผ์ •์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์—๊ฒŒ SYN ํŒจํ‚ท์„ ๋ณด๋ƒ„ (sequence: X)
  • ์„œ๋ฒ„๊ฐ€ SYN(X)์„ ๋ฐ›๊ณ , ํด๋ผ์ด์–ธํŠธ๋กœ ๋ฐ›์•˜๋‹ค๋Š” ์‹ ํ˜ธ์ธ ACK์™€ SYNํŒจํ‚ท์„ ๋ณด๋ƒ„ (sequence: Y / ACK: X+1)
  • ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„์˜ ์‘๋‹ต์ธ ACK(X+1)์™€ SYN(Y) ํŒจํ‚ท์„ ๋ฐ›๊ณ , ACK(Y+1)๋ฅผ ์„œ๋ฒ„๋กœ ๋ณด๋ƒ„

*ACK: Acknowledgment(์Šน์ธ), ์š”์ฒญ์„ ํ™•์ธํ–ˆ๋‹ค๋Š” ์‘๋‹ต

*SYN: Synchronize(๋™์‹œ์„ฑ) Sequence Number, ์—ฐ๊ฒฐ์ด ์ด๋ฃจ์–ด์ง€๋„๋ก ์š”์ฒญํ•˜๋Š” ์˜๋ฏธ


4 way handshake

TCP๋Š” ๋ชจ๋“  ํ†ต์‹ ์ด ๋๋‚œํ›„ ์—ฐ๊ฒฐ ํ•ด์ œ๋ฅผ ์œ„ํ•ด 4๋ฒˆ์˜ ๊ณผ์ •์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

  • ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„์—๊ฒŒ ์—ฐ๊ฒฐ์„ ์ข…๋ฃŒํ•œ๋‹ค๋Š” FIN ํ”Œ๋ž˜๊ทธ๋ฅผ ๋ณด๋ƒ„
  • ์„œ๋ฒ„๋Š” FIN์„ ๋ฐ›๊ณ , ํ™•์ธํ–ˆ๋‹ค๋Š” ACK๋ฅผ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋ƒ„ (์ด๋•Œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋ณด๋‚ด๊ธฐ ์œ„ํ•ด CLOSE_WAIT ์ƒํƒœ๊ฐ€ ๋จ)
  • ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ๋‘ ๋ณด๋‚ด๊ณ , ์„œ๋ฒ„๋Š” ์—ฐ๊ฒฐ์ด ์ข…๋ฃŒ๋˜์—ˆ๋‹ค๋Š” FIN ํ”Œ๋ž˜๊ทธ๋ฅผ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ณด๋ƒ„
  • ํด๋ผ์ด์–ธํŠธ๋Š” FIN์„ ๋ฐ›๊ณ , ํ™•์ธํ–ˆ๋‹ค๋Š” ACK๋ฅผ ์„œ๋ฒ„์—๊ฒŒ ๋ณด๋ƒ„(์•„์ง ์„œ๋ฒ„๋กœ๋ถ€ํ„ฐ ๋ฐ›์ง€ ๋ชปํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ์„ ์ˆ˜ ์žˆ์–ด TIME_WAIT์ƒํƒœ)
    • ์„œ๋ฒ„๋Š” ACK๋ฅผ ๋ฐ›์„ ์ดํ›„ ์†Œ์ผ“์„ ๋‹ซ์Œ (CLOESED)
    • TIME_WAIT ์‹œ๊ฐ„์ด ๋๋‚˜๋ฉด ํด๋ผ์ด์–ธํŠธ๋„ ๋‹ซ์Œ (CLOSED)

 


[์ฐธ๊ณ ]

https://velog.io/@leeesangheee/%EB%84%A4%ED%8A%B8%EC%9B%8C%ED%81%AC.-TCP-3-way-Handshake

 

๋„คํŠธ์›Œํฌ. TCP 3-way Handshake

TCP 3-way Handshake

velog.io

 

https://github.com/gyoogle/tech-interview-for-developer/blob/master/Computer%20Science/Network/TCP%203%20way%20handshake%20%26%204%20way%20handshake.md#tcp-3-way-handshake--4-way-handshake