๐ŸŒ ๋„คํŠธ์›Œํฌ์™€ ์†Œ์ผ“ ์ดํ•ด

๐Ÿ”Œ ์†Œ์ผ“

TCP/IP ํ”„๋กœํ† ์ฝœ์˜ ํ”„๋กœ๊ทธ๋ž˜๋จธ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•ด์ฃผ๋Š”๊ฒƒ.

3๊ฐ€์ง€ ๊ณผ์ •์œผ๋กœ ์‚ฌ์šฉ

  1. ์†Œ์ผ“ ์ƒ์„ฑ OPEN
  2. ์†Œ์ผ“์„ ํ†ตํ•œ ์†ก/์ˆ˜์‹ 
  3. ์†Œ์ผ“ ์†Œ๋ฉธ CLOSE

๐Ÿ’ป Socket ํ”„๋กœ๊ทธ๋ž˜๋ฐ

int sockfd = socket ( PF_INET, SOCK_STREAM, IPPROTO_TCP );
domain
ํ”„๋กœํ† ์ฝœ ์ฒด๊ณ„ (Protocol Family) ์˜๋ฏธ
PF_INET IPv4 ์ธํ„ฐ๋„ท ํ”„๋กœํ† ์ฝœ
PF_INET6 IPv6 ์ธํ„ฐ๋„ท ํ”„๋กœํ† ์ฝœ
PF_LOCAL ๋กœ์ปฌ ํ†ต์‹ ์„ ์œ„ํ•œ UNIX ํ”„๋กœํ† ์ฝœ ์ฒด๊ณ„
PF_PACKET Low Level ์†Œ์ผ“์„ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ ์ฒด๊ณ„
PF_IPX IPX ๋…ธ๋ฒจ ํ”„๋กœํ† ์ฝœ ์ฒด๊ณ„
type
  • ๐Ÿ“ž SOCK_STREAM ( ์ „ํ™” )

ServerSocket Socket

- TCP ํ†ต์‹ ์†Œ์ผ“์ด๋‹ค. - stream๋ฐฉ์‹์˜ ์—ฐ๊ฒฐ์ง€ํ–ฅ ์†Œ์ผ“ ์ƒ์„ฑ. - ์–‘๋ฐฉํ–ฅ ํ†ต์‹  - byte๋ฅผ ์ฃผ๊ณ ๋ฐ›๋Š” ๊ฐ€๋ณ€๊ธธ์ด stream์ด๋‹ค. - ์ „๋‹ฌ๋œ ๋ชจ๋“  ๋ฐ์ดํ„ฐ๋Š” ๋ฌด๊ฒฐ์„ฑ ์ด ๋ณด์žฅ๋œ๋‹ค.

  • ๐ŸŽฅ SOCK_DATAGRAM ( ์ŠคํŠธ๋ฆฌ๋ฐ )

DatagramSocket

- UDP ํ†ต์‹  ์†Œ์ผ“์ด๋‹ค. - datagram ๋ฐฉ์‹์˜ ๋น„๋™๊ธฐ ์†Œ์ผ“์„ ์ƒ์„ฑ. - ์–‘๋ฐฉํ–ฅ ํ†ต์‹  - ๊ณ ์ •๊ธธ์ด์˜ ๋ฉ”์‹œ์ง€๋ฅผ ์‚ฌ์šฉ - ์‹ ๋ขฐ์„ฑ ๋ณด์žฅ โŒ

๐Ÿ“ ํฌํŠธ๋ฒˆํ˜ธ

- ๊ฐ๊ฐ์˜ ์†Œ์ผ“์„ ๊ตฌ๋ถ„ ํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ

์•„ํŒŒํŠธ(host)์— ์‚ฌ๋Š” ์‚ฌ๋žŒ(process)์—๊ฒŒ ํŽธ์ง€(data)๋ฅผ ๋ณด๋‚ผ๋•Œ ๋™(IP)๊ณผ ํ˜ธ(Port)๋ฅผ ๋ด‰ํˆฌ(Packet)์— ๊ธฐ์ž…ํ•ด์•ผ ํ•œ๋‹ค.

ํฌํŠธ์˜ ์ค‘๋ณต์€ ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

ํ•˜์ง€๋งŒ, ๊ฐ™์€ UDP ํฌํŠธ์™€ TCP ํฌํŠธ๋Š” ์ค‘๋ณตํ•˜์—ฌ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋‹ค.